LCOV - code coverage report
Current view: top level - reportdesign/source/filter/xml - xmlExport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 939 0.0 %
Date: 2014-11-03 Functions: 0 62 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "xmlExport.hxx"
      21             : #include "xmlAutoStyle.hxx"
      22             : #include <xmloff/ProgressBarHelper.hxx>
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include <xmloff/txtimp.hxx>
      25             : #include <xmloff/xmlnmspe.hxx>
      26             : #include <xmloff/xmluconv.hxx>
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include <comphelper/types.hxx>
      29             : #include "xmlEnums.hxx"
      30             : #include <xmloff/txtprmap.hxx>
      31             : #include <xmloff/numehelp.hxx>
      32             : #include "xmlHelper.hxx"
      33             : #include "xmlstrings.hrc"
      34             : #include "xmlPropertyHandler.hxx"
      35             : #include <sax/tools/converter.hxx>
      36             : #include <com/sun/star/awt/ImagePosition.hpp>
      37             : #include <com/sun/star/util/NumberFormat.hpp>
      38             : #include <com/sun/star/util/MeasureUnit.hpp>
      39             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      40             : #include <com/sun/star/awt/TextAlign.hpp>
      41             : #include <com/sun/star/report/GroupOn.hpp>
      42             : #include <com/sun/star/report/XFixedText.hpp>
      43             : #include <com/sun/star/report/XImageControl.hpp>
      44             : #include <com/sun/star/report/XShape.hpp>
      45             : #include <com/sun/star/drawing/XShape.hpp>
      46             : #include <com/sun/star/drawing/XShapes.hpp>
      47             : #include <com/sun/star/report/XFunction.hpp>
      48             : #include <com/sun/star/awt/FontDescriptor.hpp>
      49             : #include <com/sun/star/text/TextContentAnchorType.hpp>
      50             : #include <com/sun/star/table/BorderLine2.hpp>
      51             : #include <com/sun/star/table/BorderLineStyle.hpp>
      52             : #include <com/sun/star/report/XFixedLine.hpp>
      53             : #include <com/sun/star/frame/XController.hpp>
      54             : #include "RptDef.hxx"
      55             : #include <vcl/svapp.hxx>
      56             : #include <osl/mutex.hxx>
      57             : #include <sal/macros.h>
      58             : 
      59             : #include <boost/bind.hpp>
      60             : 
      61             : 
      62             : namespace rptxml
      63             : {
      64             :     using namespace xmloff;
      65             :     using namespace comphelper;
      66             :     using namespace ::com::sun::star;
      67             :     using namespace ::com::sun::star::report;
      68             :     using namespace ::com::sun::star::uno;
      69             :     using namespace ::com::sun::star::util;
      70             :     using namespace ::com::sun::star::xml;
      71             : 
      72             : 
      73           0 :     Reference< XInterface > ORptExportHelper::create(Reference< XComponentContext > const & xContext)
      74             :     {
      75           0 :         return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), EXPORT_SETTINGS ));
      76             :     }
      77             : 
      78           0 :     OUString ORptExportHelper::getImplementationName_Static(  ) throw (RuntimeException)
      79             :     {
      80           0 :         return OUString("com.sun.star.comp.report.XMLSettingsExporter");
      81             :     }
      82             : 
      83           0 :     Sequence< OUString > ORptExportHelper::getSupportedServiceNames_Static(  ) throw(RuntimeException)
      84             :     {
      85           0 :         Sequence< OUString > aSupported(1);
      86           0 :         aSupported[0] = "com.sun.star.document.ExportFilter";
      87           0 :         return aSupported;
      88             :     }
      89             : 
      90           0 :     Reference< XInterface > ORptContentExportHelper::create(Reference< XComponentContext > const & xContext)
      91             :     {
      92           0 :         return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), EXPORT_CONTENT ));
      93             :     }
      94             : 
      95           0 :     OUString ORptContentExportHelper::getImplementationName_Static(  ) throw (RuntimeException)
      96             :     {
      97           0 :         return OUString("com.sun.star.comp.report.XMLContentExporter");
      98             :     }
      99             : 
     100           0 :     Sequence< OUString > ORptContentExportHelper::getSupportedServiceNames_Static(  ) throw(RuntimeException)
     101             :     {
     102           0 :         Sequence< OUString > aSupported(1);
     103           0 :         aSupported[0] = "com.sun.star.document.ExportFilter";
     104           0 :         return aSupported;
     105             :     }
     106             : 
     107             : 
     108           0 :     Reference< XInterface > ORptStylesExportHelper::create(Reference< XComponentContext > const & xContext)
     109             :     {
     110             :         return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), EXPORT_STYLES | EXPORT_MASTERSTYLES | EXPORT_AUTOSTYLES |
     111           0 :             EXPORT_FONTDECLS|EXPORT_OASIS ));
     112             :     }
     113             : 
     114           0 :     OUString ORptStylesExportHelper::getImplementationName_Static(  ) throw (RuntimeException)
     115             :     {
     116           0 :         return OUString("com.sun.star.comp.report.XMLStylesExporter");
     117             :     }
     118             : 
     119           0 :     Sequence< OUString > ORptStylesExportHelper::getSupportedServiceNames_Static(  ) throw(RuntimeException)
     120             :     {
     121           0 :         Sequence< OUString > aSupported(1);
     122           0 :         aSupported[0] = "com.sun.star.document.ExportFilter";
     123           0 :         return aSupported;
     124             :     }
     125             : 
     126             : 
     127           0 :     Reference< XInterface > ORptMetaExportHelper::create(Reference< XComponentContext > const & xContext)
     128             :     {
     129           0 :         return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), EXPORT_META ));
     130             :     }
     131             : 
     132           0 :     OUString ORptMetaExportHelper::getImplementationName_Static(  ) throw (RuntimeException)
     133             :     {
     134           0 :         return OUString("com.sun.star.comp.report.XMLMetaExporter");
     135             :     }
     136             : 
     137           0 :     Sequence< OUString > ORptMetaExportHelper::getSupportedServiceNames_Static(  ) throw(RuntimeException)
     138             :     {
     139           0 :         Sequence< OUString > aSupported(1);
     140           0 :         aSupported[0] = "com.sun.star.document.ExportFilter";
     141           0 :         return aSupported;
     142             :     }
     143             : 
     144             : 
     145           0 :     Reference< XInterface > ODBFullExportHelper::create(Reference< XComponentContext > const & xContext)
     146             :     {
     147           0 :         return static_cast< XServiceInfo* >(new ORptExport(xContext, getImplementationName_Static(), EXPORT_ALL));
     148             :     }
     149             : 
     150           0 :     OUString ODBFullExportHelper::getImplementationName_Static(  ) throw (RuntimeException)
     151             :     {
     152           0 :         return OUString("com.sun.star.comp.report.XMLFullExporter");
     153             :     }
     154             : 
     155           0 :     Sequence< OUString > ODBFullExportHelper::getSupportedServiceNames_Static(  ) throw(RuntimeException)
     156             :     {
     157           0 :         Sequence< OUString > aSupported(1);
     158           0 :         aSupported[0] = "com.sun.star.document.ExportFilter";
     159           0 :         return aSupported;
     160             :     }
     161             : 
     162             : 
     163             : 
     164           0 :     class OSpecialHandleXMLExportPropertyMapper : public SvXMLExportPropertyMapper
     165             :     {
     166             :     public:
     167           0 :         OSpecialHandleXMLExportPropertyMapper(const rtl::Reference< XMLPropertySetMapper >& rMapper) : SvXMLExportPropertyMapper(rMapper )
     168             :         {
     169           0 :         }
     170             :         /** this method is called for every item that has the
     171             :         MID_FLAG_SPECIAL_ITEM_EXPORT flag set */
     172           0 :         virtual void handleSpecialItem(
     173             :                 SvXMLAttributeList& /*rAttrList*/,
     174             :                 const XMLPropertyState& /*rProperty*/,
     175             :                 const SvXMLUnitConverter& /*rUnitConverter*/,
     176             :                 const SvXMLNamespaceMap& /*rNamespaceMap*/,
     177             :                 const ::std::vector< XMLPropertyState >* /*pProperties*/ = 0,
     178             :                 sal_uInt32 /*nIdx*/ = 0 ) const SAL_OVERRIDE
     179             :         {
     180             :             // nothing to do here
     181           0 :         }
     182             :     };
     183             : 
     184           0 : void lcl_adjustColumnSpanOverRows(ORptExport::TSectionsGrid& _rGrid)
     185             : {
     186           0 :     ORptExport::TSectionsGrid::iterator aSectionIter = _rGrid.begin();
     187           0 :     ORptExport::TSectionsGrid::iterator aSectionEnd = _rGrid.end();
     188           0 :     for (;aSectionIter != aSectionEnd ; ++aSectionIter)
     189             :     {
     190           0 :         ORptExport::TGrid::iterator aRowIter = aSectionIter->second.begin();
     191           0 :         ORptExport::TGrid::iterator aRowEnd = aSectionIter->second.end();
     192           0 :         for (; aRowIter != aRowEnd; ++aRowIter)
     193             :         {
     194           0 :             if ( aRowIter->first )
     195             :             {
     196           0 :                 ::std::vector< ORptExport::TCell >::iterator aColIter = aRowIter->second.begin();
     197           0 :                 ::std::vector< ORptExport::TCell >::iterator aColEnd = aRowIter->second.end();
     198           0 :                 for (; aColIter != aColEnd; ++aColIter)
     199             :                 {
     200           0 :                     if ( aColIter->nRowSpan > 1 )
     201             :                     {
     202           0 :                         sal_Int32 nColSpan = aColIter->nColSpan;
     203           0 :                         sal_Int32 nColIndex = aColIter - aRowIter->second.begin();
     204           0 :                         for (sal_Int32 i = 1; i < aColIter->nRowSpan; ++i)
     205             :                         {
     206           0 :                             (aRowIter+i)->second[nColIndex].nColSpan = nColSpan;
     207             :                         }
     208             :                     }
     209             :                 }
     210             :             }
     211             :         }
     212             :     }
     213           0 : }
     214             : 
     215           0 : ORptExport::ORptExport(const Reference< XComponentContext >& _rxContext, OUString const & implementationName, sal_uInt16 nExportFlag)
     216             : : SvXMLExport( util::MeasureUnit::MM_100TH, _rxContext, implementationName, XML_REPORT, EXPORT_OASIS)
     217           0 : ,m_bAllreadyFilled(false)
     218             : {
     219           0 :     setExportFlags( EXPORT_OASIS | nExportFlag);
     220           0 :     GetMM100UnitConverter().SetCoreMeasureUnit(css::util::MeasureUnit::MM_100TH);
     221           0 :     GetMM100UnitConverter().SetXMLMeasureUnit(css::util::MeasureUnit::CM);
     222             : 
     223             :     // (getExportFlags() & EXPORT_CONTENT) != 0 ? : XML_N_OOO
     224           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE ), XML_NAMESPACE_OFFICE );
     225           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
     226             : 
     227           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_RPT), GetXMLToken(XML_N_RPT), XML_NAMESPACE_REPORT );
     228           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_SVG), GetXMLToken(XML_N_SVG_COMPAT),  XML_NAMESPACE_SVG );
     229           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_FORM), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM );
     230           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_DRAW), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW );
     231           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_TEXT), GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT );
     232             : 
     233             : 
     234           0 :     if( (getExportFlags() & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS) ) != 0 )
     235           0 :         _GetNamespaceMap().Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
     236             : 
     237           0 :     if( (getExportFlags() & (EXPORT_META|EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_SETTINGS) ) != 0 )
     238             :     {
     239           0 :         _GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
     240             :     }
     241           0 :     if( (getExportFlags() & EXPORT_SETTINGS) != 0 )
     242             :     {
     243           0 :         _GetNamespaceMap().Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
     244             :     }
     245             : 
     246           0 :     if( (getExportFlags() & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_FONTDECLS) ) != 0 )
     247             :     {
     248           0 :         _GetNamespaceMap().Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
     249             :     }
     250             :     // RDFa: needed for content and header/footer styles
     251           0 :     if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
     252             :     {
     253           0 :         _GetNamespaceMap().Add( GetXMLToken(XML_NP_XHTML),GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
     254             :     }
     255             :     // GRDDL: to convert RDFa and meta.xml to RDF
     256           0 :     if( (getExportFlags() & (EXPORT_META|EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
     257             :     {
     258           0 :         _GetNamespaceMap().Add( GetXMLToken(XML_NP_GRDDL),GetXMLToken(XML_N_GRDDL), XML_NAMESPACE_GRDDL );
     259             :     }
     260             : 
     261           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE );
     262           0 :     _GetNamespaceMap().Add( GetXMLToken(XML_NP_NUMBER), GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER );
     263             : 
     264           0 :     m_sTableStyle = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_STYLE_NAME) );
     265           0 :     m_sColumnStyle = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_COLUMN) );
     266           0 :     m_sCellStyle = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_REPORT, GetXMLToken(XML_STYLE_NAME) );
     267             : 
     268             : 
     269           0 :     m_xPropHdlFactory = new OXMLRptPropHdlFactory();
     270           0 :     rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory();
     271           0 :     rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper1 = new XMLPropertySetMapper(OXMLHelper::GetTableStyleProps(),xFac, true);
     272           0 :     rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper2 = new XMLTextPropertySetMapper(TEXT_PROP_MAP_TABLE_DEFAULTS, true );
     273           0 :     xTableStylesPropertySetMapper1->AddMapperEntry(xTableStylesPropertySetMapper2);
     274             : 
     275           0 :     m_xTableStylesExportPropertySetMapper = new SvXMLExportPropertyMapper(xTableStylesPropertySetMapper1);
     276             : 
     277           0 :     m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylePropertyMap( false, true);
     278           0 :     m_xCellStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(m_xCellStylesPropertySetMapper);
     279           0 :     m_xCellStylesExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(*this));
     280             : 
     281           0 :     rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetColumnStyleProps(), m_xPropHdlFactory, true);
     282           0 :     m_xColumnStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(xColumnStylesPropertySetMapper);
     283             : 
     284           0 :     rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetRowStyleProps(), m_xPropHdlFactory, true);
     285           0 :     m_xRowStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(xRowStylesPropertySetMapper);
     286             : 
     287           0 :     rtl::Reference < XMLPropertySetMapper > xPropMapper(new XMLTextPropertySetMapper( TEXT_PROP_MAP_PARA, true ));
     288           0 :     m_xParaPropMapper = new OSpecialHandleXMLExportPropertyMapper( xPropMapper);
     289             : 
     290           0 :     OUString sFamily( GetXMLToken(XML_PARAGRAPH) );
     291           0 :     OUString aPrefix( 'P');
     292             :     GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_TEXT_PARAGRAPH, sFamily,
     293           0 :                               m_xParaPropMapper, aPrefix );
     294             : 
     295             :     GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_CELL, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME),
     296           0 :         m_xCellStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX));
     297             :     GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_COLUMN, OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME),
     298           0 :         m_xColumnStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX));
     299             :     GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_ROW, OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME),
     300           0 :         m_xRowStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX));
     301             :     GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_TABLE, OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME),
     302           0 :         m_xTableStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX));
     303           0 : }
     304             : 
     305           0 : Reference< XInterface > ORptExport::create(Reference< XComponentContext > const & xContext)
     306             : {
     307           0 :     return *(new ORptExport(xContext, getImplementationName_Static(), EXPORT_CONTENT | EXPORT_AUTOSTYLES | EXPORT_FONTDECLS));
     308             : }
     309             : 
     310             : 
     311           0 : OUString ORptExport::getImplementationName_Static(  ) throw(uno::RuntimeException)
     312             : {
     313           0 :     return OUString("com.sun.star.comp.report.ExportFilter");
     314             : }
     315             : 
     316             : 
     317           0 : uno::Sequence< OUString > ORptExport::getSupportedServiceNames_Static(  ) throw(uno::RuntimeException)
     318             : {
     319           0 :     uno::Sequence< OUString > aServices(1);
     320           0 :     aServices.getArray()[0] = "com.sun.star.document.ExportFilter";
     321             : 
     322           0 :     return aServices;
     323             : }
     324             : 
     325             : 
     326           0 : void ORptExport::exportFunctions(const Reference<XIndexAccess>& _xFunctions)
     327             : {
     328           0 :     const sal_Int32 nCount = _xFunctions->getCount();
     329           0 :     for (sal_Int32 i = 0; i< nCount; ++i)
     330             :     {
     331           0 :         uno::Reference< report::XFunction> xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW);
     332             :         OSL_ENSURE(xFunction.is(),"Function object is NULL!");
     333           0 :         exportFunction(xFunction);
     334           0 :     }
     335           0 : }
     336             : 
     337           0 : void ORptExport::exportFunction(const uno::Reference< XFunction>& _xFunction)
     338             : {
     339           0 :     exportFormula(XML_FORMULA,_xFunction->getFormula());
     340           0 :     beans::Optional< OUString> aInitial = _xFunction->getInitialFormula();
     341           0 :     if ( aInitial.IsPresent && !aInitial.Value.isEmpty() )
     342           0 :         exportFormula(XML_INITIAL_FORMULA ,aInitial.Value );
     343           0 :     AddAttribute( XML_NAMESPACE_REPORT, XML_NAME , _xFunction->getName() );
     344           0 :     if ( _xFunction->getPreEvaluated() )
     345           0 :         AddAttribute( XML_NAMESPACE_REPORT, XML_PRE_EVALUATED , XML_TRUE );
     346           0 :     if ( _xFunction->getDeepTraversing() )
     347           0 :         AddAttribute( XML_NAMESPACE_REPORT, XML_DEEP_TRAVERSING , XML_TRUE );
     348             : 
     349           0 :     SvXMLElementExport aFunction(*this,XML_NAMESPACE_REPORT, XML_FUNCTION, true, true);
     350           0 : }
     351             : 
     352           0 : void ORptExport::exportMasterDetailFields(const Reference<XReportComponent>& _xReportComponet)
     353             : {
     354           0 :     const uno::Sequence< OUString> aMasterFields = _xReportComponet->getMasterFields();
     355           0 :     if ( aMasterFields.getLength() )
     356             :     {
     357           0 :         SvXMLElementExport aElement(*this,XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELDS, true, true);
     358           0 :         const uno::Sequence< OUString> aDetailFields = _xReportComponet->getDetailFields();
     359             : 
     360             :         OSL_ENSURE(aDetailFields.getLength() == aMasterFields.getLength(),"not equal length for master and detail fields!");
     361             : 
     362           0 :         const OUString* pDetailFieldsIter = aDetailFields.getConstArray();
     363           0 :         const OUString* pIter = aMasterFields.getConstArray();
     364           0 :         const OUString* pEnd   = pIter + aMasterFields.getLength();
     365           0 :         for(;pIter != pEnd;++pIter,++pDetailFieldsIter)
     366             :         {
     367           0 :             AddAttribute( XML_NAMESPACE_REPORT, XML_MASTER , *pIter );
     368           0 :             if ( !pDetailFieldsIter->isEmpty() )
     369           0 :                 AddAttribute( XML_NAMESPACE_REPORT, XML_DETAIL , *pDetailFieldsIter );
     370           0 :             SvXMLElementExport aPair(*this,XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELD, true, true);
     371           0 :         }
     372           0 :     }
     373           0 : }
     374             : 
     375           0 : void ORptExport::exportReport(const Reference<XReportDefinition>& _xReportDefinition)
     376             : {
     377           0 :     if ( _xReportDefinition.is() )
     378             :     {
     379           0 :         exportFunctions(_xReportDefinition->getFunctions().get());
     380           0 :         exportGroupsExpressionAsFunction(_xReportDefinition->getGroups());
     381             : 
     382           0 :         if ( _xReportDefinition->getReportHeaderOn() )
     383             :         {
     384           0 :             SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_REPORT_HEADER, true, true);
     385           0 :             exportSection(_xReportDefinition->getReportHeader());
     386             :         }
     387           0 :         if ( _xReportDefinition->getPageHeaderOn() )
     388             :         {
     389           0 :             OUStringBuffer sValue;
     390           0 :             sal_uInt16 nRet = _xReportDefinition->getPageHeaderOption();
     391           0 :             const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetReportPrintOptions();
     392           0 :             if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
     393           0 :                 AddAttribute(XML_NAMESPACE_REPORT, XML_PAGE_PRINT_OPTION,sValue.makeStringAndClear());
     394             : 
     395           0 :             SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_PAGE_HEADER, true, true);
     396           0 :             exportSection(_xReportDefinition->getPageHeader(),true);
     397             :         }
     398             : 
     399           0 :         exportGroup(_xReportDefinition,0);
     400             : 
     401           0 :         if ( _xReportDefinition->getPageFooterOn() )
     402             :         {
     403           0 :             OUStringBuffer sValue;
     404           0 :             sal_uInt16 nRet = _xReportDefinition->getPageFooterOption();
     405           0 :             const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetReportPrintOptions();
     406           0 :             if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
     407           0 :                 AddAttribute(XML_NAMESPACE_REPORT, XML_PAGE_PRINT_OPTION,sValue.makeStringAndClear());
     408           0 :             SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_PAGE_FOOTER, true, true);
     409           0 :             exportSection(_xReportDefinition->getPageFooter(),true);
     410             :         }
     411           0 :         if ( _xReportDefinition->getReportFooterOn() )
     412             :         {
     413           0 :             SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_REPORT_FOOTER, true, true);
     414           0 :             exportSection(_xReportDefinition->getReportFooter());
     415             :         }
     416             :     }
     417           0 : }
     418             : 
     419           0 : void ORptExport::exportComponent(const Reference<XReportComponent>& _xReportComponent)
     420             : {
     421             :     OSL_ENSURE(_xReportComponent.is(),"No component interface!");
     422           0 :     if ( !_xReportComponent.is() )
     423           0 :         return;
     424             : 
     425           0 :     AddAttribute(XML_NAMESPACE_DRAW, XML_NAME,_xReportComponent->getName());
     426             : 
     427           0 :     SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_REPORT_COMPONENT, false, false);
     428             : }
     429             : 
     430           0 : void ORptExport::exportFormatConditions(const Reference<XReportControlModel>& _xReportElement)
     431             : {
     432             :     OSL_ENSURE(_xReportElement.is(),"_xReportElement is NULL -> GPF");
     433           0 :     const sal_Int32 nCount = _xReportElement->getCount();
     434             :     try
     435             :     {
     436           0 :         for (sal_Int32 i = 0; i < nCount ; ++i)
     437             :         {
     438           0 :             uno::Reference< report::XFormatCondition > xCond(_xReportElement->getByIndex(i),uno::UNO_QUERY);
     439           0 :             if ( !xCond->getEnabled() )
     440           0 :                 AddAttribute(XML_NAMESPACE_REPORT, XML_ENABLED,XML_FALSE);
     441             : 
     442           0 :             AddAttribute(XML_NAMESPACE_REPORT, XML_FORMULA,xCond->getFormula());
     443             : 
     444           0 :             exportStyleName(xCond.get(),GetAttrList(),m_sCellStyle);
     445           0 :             SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_FORMAT_CONDITION, true, true);
     446           0 :         }
     447             :     }
     448           0 :     catch(uno::Exception&)
     449             :     {
     450             :         OSL_FAIL("Can not access format condition!");
     451             :     }
     452           0 : }
     453             : 
     454           0 : void ORptExport::exportReportElement(const Reference<XReportControlModel>& _xReportElement)
     455             : {
     456             :     OSL_ENSURE(_xReportElement.is(),"_xReportElement is NULL -> GPF");
     457           0 :     if ( !_xReportElement->getPrintWhenGroupChange() )
     458           0 :         AddAttribute(XML_NAMESPACE_REPORT, XML_PRINT_WHEN_GROUP_CHANGE, XML_FALSE );
     459             : 
     460           0 :     if ( !_xReportElement->getPrintRepeatedValues() )
     461           0 :         AddAttribute(XML_NAMESPACE_REPORT, XML_PRINT_REPEATED_VALUES,XML_FALSE);
     462             : 
     463           0 :     SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_REPORT_ELEMENT, true, true);
     464           0 :     if ( _xReportElement->getCount() )
     465             :     {
     466           0 :         exportFormatConditions(_xReportElement);
     467             :     }
     468             : 
     469           0 :     OUString sExpr = _xReportElement->getConditionalPrintExpression();
     470           0 :     if ( !sExpr.isEmpty() )
     471             :     {
     472           0 :         exportFormula(XML_FORMULA,sExpr);
     473           0 :         SvXMLElementExport aPrintExpr(*this,XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION, true, true);
     474             :     }
     475             : 
     476             :     // only export when parent exists
     477           0 :     uno::Reference< report::XSection> xParent(_xReportElement->getParent(),uno::UNO_QUERY);
     478           0 :     if ( xParent.is() )
     479           0 :         exportComponent(_xReportElement.get());
     480           0 : }
     481             : 
     482           0 : void lcl_calculate(const ::std::vector<sal_Int32>& _aPosX,const ::std::vector<sal_Int32>& _aPosY,ORptExport::TGrid& _rColumns)
     483             : {
     484           0 :     sal_Int32 nCountX = _aPosX.size() - 1;
     485           0 :     sal_Int32 nCountY = _aPosY.size() - 1;
     486           0 :     for (sal_Int32 j = 0; j < nCountY; ++j)
     487             :     {
     488           0 :         sal_Int32 nHeight = _aPosY[j+1] - _aPosY[j];
     489           0 :         if ( nHeight )
     490           0 :             for (sal_Int32 i = 0; i < nCountX ; ++i)
     491             :             {
     492           0 :                 _rColumns[j].second[i] = ORptExport::TCell(_aPosX[i+1] - _aPosX[i],nHeight,1,1);
     493           0 :                 _rColumns[j].second[i].bSet = true;
     494             :             }
     495             :     }
     496           0 : }
     497             : 
     498           0 : void ORptExport::collectStyleNames(sal_Int32 _nFamily,const ::std::vector< sal_Int32>& _aSize, ORptExport::TStringVec& _rStyleNames)
     499             : {
     500           0 :     ::std::vector< XMLPropertyState > aPropertyStates;
     501           0 :     aPropertyStates.push_back(XMLPropertyState(0));
     502           0 :     ::std::vector<sal_Int32>::const_iterator aIter = _aSize.begin();
     503           0 :     ::std::vector<sal_Int32>::const_iterator aIter2 = aIter + 1;
     504           0 :     ::std::vector<sal_Int32>::const_iterator aEnd = _aSize.end();
     505           0 :     for (;aIter2 != aEnd ; ++aIter,++aIter2)
     506             :     {
     507           0 :         sal_Int32 nValue = static_cast<sal_Int32>(*aIter2 - *aIter);
     508           0 :         aPropertyStates[0].maValue <<= nValue;
     509           0 :         _rStyleNames.push_back(GetAutoStylePool()->Add(_nFamily, aPropertyStates ));
     510           0 :     }
     511           0 : }
     512             : 
     513           0 : void ORptExport::exportSectionAutoStyle(const Reference<XSection>& _xProp)
     514             : {
     515             :     OSL_ENSURE(_xProp != NULL,"Section is NULL -> GPF");
     516           0 :     exportAutoStyle(_xProp);
     517             : 
     518           0 :     Reference<XReportDefinition> xReport = _xProp->getReportDefinition();
     519           0 :     const awt::Size aSize   = rptui::getStyleProperty<awt::Size>(xReport,PROPERTY_PAPERSIZE);
     520           0 :     const sal_Int32 nOffset = rptui::getStyleProperty<sal_Int32>(xReport,PROPERTY_LEFTMARGIN);
     521           0 :     const sal_Int32 nCount  = _xProp->getCount();
     522             : 
     523           0 :     ::std::vector<sal_Int32> aColumnPos;
     524           0 :     aColumnPos.reserve(2*(nCount + 1));
     525           0 :     aColumnPos.push_back(nOffset);
     526           0 :     aColumnPos.push_back(aSize.Width - rptui::getStyleProperty<sal_Int32>(xReport,PROPERTY_RIGHTMARGIN));
     527             : 
     528           0 :     ::std::vector<sal_Int32> aRowPos;
     529           0 :     aRowPos.reserve(2*(nCount + 1));
     530           0 :     aRowPos.push_back(0);
     531           0 :     aRowPos.push_back(_xProp->getHeight());
     532             : 
     533             :     sal_Int32 i;
     534           0 :     for (i = 0 ; i< nCount ; ++i)
     535             :     {
     536           0 :         Reference<XReportComponent> xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY);
     537           0 :         uno::Reference< XShape> xShape(xReportElement,uno::UNO_QUERY);
     538           0 :         if ( xShape.is() )
     539           0 :             continue;
     540             :         OSL_ENSURE( xReportElement.is(),"NULL Element in Section!" );
     541           0 :         if ( !xReportElement.is() )
     542           0 :             continue;
     543           0 :         sal_Int32 nX = xReportElement->getPositionX();
     544           0 :         aColumnPos.push_back(nX);
     545           0 :         Reference<XFixedLine> xFixedLine(xReportElement,uno::UNO_QUERY);
     546           0 :         if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
     547             :         {
     548           0 :             sal_Int32 nWidth = static_cast<sal_Int32>(xReportElement->getWidth()*0.5);
     549           0 :             nX += nWidth;
     550           0 :             aColumnPos.push_back(nX);
     551           0 :             nX += xReportElement->getWidth() - nWidth;
     552             :         }
     553             :         else
     554           0 :             nX += xReportElement->getWidth();
     555           0 :         aColumnPos.push_back(nX); // --nX why?
     556             : 
     557           0 :         sal_Int32 nY = xReportElement->getPositionY();
     558           0 :         aRowPos.push_back(nY);
     559           0 :         nY += xReportElement->getHeight();
     560           0 :         aRowPos.push_back(nY); // --nY why?
     561           0 :     }
     562             : 
     563           0 :     ::std::sort(aColumnPos.begin(),aColumnPos.end(),::std::less<sal_Int32>());
     564           0 :     aColumnPos.erase(::std::unique(aColumnPos.begin(),aColumnPos.end()),aColumnPos.end());
     565             : 
     566           0 :     ::std::sort(aRowPos.begin(),aRowPos.end(),::std::less<sal_Int32>());
     567           0 :     aRowPos.erase(::std::unique(aRowPos.begin(),aRowPos.end()),aRowPos.end());
     568             : 
     569             :     TSectionsGrid::iterator aInsert = m_aSectionsGrid.insert(
     570             :         TSectionsGrid::value_type(
     571           0 :                                     _xProp.get(),
     572           0 :                                     TGrid(aRowPos.size() - 1,TGrid::value_type(sal_False,TRow(aColumnPos.size() - 1)))
     573             :                                   )
     574           0 :         ).first;
     575           0 :     lcl_calculate(aColumnPos,aRowPos,aInsert->second);
     576             : 
     577           0 :     TGridStyleMap::iterator aPos = m_aColumnStyleNames.insert(TGridStyleMap::value_type(_xProp.get(),TStringVec())).first;
     578           0 :     collectStyleNames(XML_STYLE_FAMILY_TABLE_COLUMN,aColumnPos,aPos->second);
     579           0 :     aPos = m_aRowStyleNames.insert(TGridStyleMap::value_type(_xProp.get(),TStringVec())).first;
     580           0 :     collectStyleNames(XML_STYLE_FAMILY_TABLE_ROW,aRowPos,aPos->second);
     581             : 
     582           0 :     sal_Int32 x1 = 0;
     583           0 :     sal_Int32 y1 = 0;
     584           0 :     sal_Int32 x2 = 0;
     585           0 :     sal_Int32 y2 = 0;
     586           0 :     sal_Int32 xi = 0;
     587           0 :     sal_Int32 yi = 0;
     588           0 :     bool isOverlap = false;
     589             : 
     590           0 :     for (i = 0 ; i< nCount ; ++i)
     591             :     {
     592           0 :         Reference<XReportComponent> xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY);
     593           0 :         uno::Reference< XShape> xShape(xReportElement,uno::UNO_QUERY);
     594           0 :         if ( xShape.is() )
     595           0 :             continue;
     596           0 :         sal_Int32 nPos = xReportElement->getPositionX();
     597           0 :         x1 = (::std::find(aColumnPos.begin(),aColumnPos.end(),nPos) - aColumnPos.begin());
     598           0 :         Reference<XFixedLine> xFixedLine(xReportElement,uno::UNO_QUERY);
     599           0 :         if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
     600           0 :             nPos += static_cast<sal_Int32>(xReportElement->getWidth()*0.5);
     601             :         else
     602           0 :             nPos += xReportElement->getWidth(); // -1 why
     603           0 :         x2 = (::std::find(aColumnPos.begin(),aColumnPos.end(),nPos) - aColumnPos.begin());
     604             : 
     605           0 :         nPos = xReportElement->getPositionY();
     606           0 :         y1 = (::std::find(aRowPos.begin(),aRowPos.end(),nPos) - aRowPos.begin());
     607           0 :         nPos += xReportElement->getHeight(); // -1 why?
     608           0 :         y2 = (::std::find(aRowPos.begin(),aRowPos.end(),nPos) - aRowPos.begin());
     609             : 
     610           0 :         isOverlap = false;
     611           0 :         yi = y1;
     612           0 :         while(yi < y2 && !isOverlap) // find overlapping controls
     613             :         {
     614           0 :             xi = x1;
     615           0 :             while(xi < x2 && !isOverlap)
     616             :             {
     617           0 :                 if ( aInsert->second[yi].second[xi].xElement.is() )
     618             :                 {
     619           0 :                     isOverlap = true;
     620             :                 }
     621           0 :                 ++xi;
     622             :             }
     623           0 :             ++yi;
     624             :         }
     625             : 
     626           0 :         if (!isOverlap)
     627             :         {
     628           0 :             yi = y1;
     629           0 :             while(yi < y2)
     630             :             {
     631           0 :                 xi = x1;
     632           0 :                 while(xi < x2)
     633             :                 {
     634           0 :                     aInsert->second[yi].second[xi] = TCell();
     635           0 :                     ++xi;
     636             :                 }
     637           0 :                 aInsert->second[yi].first = sal_True;
     638           0 :                 ++yi;
     639             :             }
     640             : 
     641           0 :             if (x2 - x1 != 0 && y2 - y1 != 0)
     642             :             {
     643           0 :                 awt::Size aElementSize = xReportElement->getSize();
     644           0 :                 if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
     645           0 :                     aElementSize.Width = static_cast<sal_Int32>(xFixedLine->getWidth()*0.5);
     646             : 
     647           0 :                 sal_Int32 nColSpan = x2 - x1;
     648           0 :                 sal_Int32 nRowSpan = y2 - y1;
     649           0 :                 aInsert->second[y1].second[x1] =
     650             :                     TCell(
     651             :                         aElementSize.Width , // -1 why?
     652             :                         aElementSize.Height, // -1 why?
     653             :                         nColSpan,
     654             :                         nRowSpan,
     655             :                         xReportElement
     656           0 :                         );
     657             :             }
     658             :         }
     659           0 :     }
     660             : 
     661           0 :     lcl_adjustColumnSpanOverRows(m_aSectionsGrid);
     662           0 :     exportReportComponentAutoStyles(_xProp);
     663           0 : }
     664             : 
     665           0 : void ORptExport::exportReportComponentAutoStyles(const Reference<XSection>& _xProp)
     666             : {
     667           0 :     const sal_Int32 nCount = _xProp->getCount();
     668           0 :     for (sal_Int32 i = 0 ; i< nCount ; ++i)
     669             :     {
     670           0 :         const Reference<XReportComponent> xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY);
     671           0 :         const Reference< report::XShape > xShape(xReportElement,uno::UNO_QUERY);
     672           0 :         if ( xShape.is() )
     673             :         {
     674           0 :             rtl::Reference< XMLShapeExport > xShapeExport = GetShapeExport();
     675           0 :             xShapeExport->seekShapes(_xProp.get());
     676           0 :             SolarMutexGuard aGuard;
     677           0 :             xShapeExport->collectShapeAutoStyles(xShape.get());
     678             :         }
     679             :         else
     680             :         {
     681           0 :             exportAutoStyle(xReportElement.get());
     682             : 
     683           0 :             Reference<XFormattedField> xFormattedField(xReportElement,uno::UNO_QUERY);
     684           0 :             if ( xFormattedField.is() )
     685             :             {
     686             :                 try
     687             :                 {
     688           0 :                     const sal_Int32 nFormatCount = xFormattedField->getCount();
     689           0 :                     for (sal_Int32 j = 0; j < nFormatCount ; ++j)
     690             :                     {
     691           0 :                         uno::Reference< report::XFormatCondition > xCond(xFormattedField->getByIndex(j),uno::UNO_QUERY);
     692           0 :                         exportAutoStyle(xCond.get(),xFormattedField);
     693           0 :                     }
     694             :                 }
     695           0 :                 catch(uno::Exception&)
     696             :                 {
     697             :                     OSL_FAIL("Can not access format condition!");
     698             :                 }
     699           0 :             }
     700             :         }
     701           0 :     }
     702           0 : }
     703             : 
     704           0 : void ORptExport::exportSection(const Reference<XSection>& _xSection,bool bHeader)
     705             : {
     706             :     OSL_ENSURE(_xSection.is(),"Section is NULL -> GPF");
     707           0 :     OUStringBuffer sValue;
     708           0 :     AddAttribute(XML_NAMESPACE_TABLE, XML_NAME,_xSection->getName());
     709             : 
     710           0 :     if ( !_xSection->getVisible() )
     711           0 :         AddAttribute(XML_NAMESPACE_REPORT, XML_VISIBLE,XML_FALSE);
     712             : 
     713           0 :     if ( !bHeader )
     714             :     {
     715           0 :         sal_uInt16 nRet = _xSection->getForceNewPage();
     716           0 :         const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetForceNewPageOptions();
     717           0 :         if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
     718           0 :             AddAttribute(XML_NAMESPACE_REPORT, XML_FORCE_NEW_PAGE,sValue.makeStringAndClear());
     719             : 
     720           0 :         nRet = _xSection->getNewRowOrCol();
     721           0 :         if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) )
     722           0 :             AddAttribute(XML_NAMESPACE_REPORT, XML_FORCE_NEW_COLUMN,sValue.makeStringAndClear());
     723           0 :         if ( _xSection->getKeepTogether() )
     724           0 :             AddAttribute(XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER, XML_TRUE );
     725             :     }
     726             : 
     727           0 :     exportStyleName(_xSection.get(),GetAttrList(),m_sTableStyle);
     728             : 
     729             :     /// TODO export as table layout
     730           0 :     SvXMLElementExport aComponents(*this,XML_NAMESPACE_TABLE, XML_TABLE, true, true);
     731             : 
     732           0 :     OUString sExpr = _xSection->getConditionalPrintExpression();
     733           0 :     if ( !sExpr.isEmpty() )
     734             :     {
     735           0 :         exportFormula(XML_FORMULA,sExpr);
     736           0 :         SvXMLElementExport aPrintExpr(*this,XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION, true, false);
     737             :     }
     738             : 
     739           0 :     exportContainer(_xSection);
     740           0 : }
     741             : 
     742           0 : void ORptExport::exportTableColumns(const Reference< XSection>& _xSection)
     743             : {
     744           0 :     SvXMLElementExport aColumns(*this,XML_NAMESPACE_TABLE, XML_TABLE_COLUMNS, true, true);
     745           0 :     TGridStyleMap::iterator aColFind = m_aColumnStyleNames.find(_xSection.get());
     746             :     OSL_ENSURE(aColFind != m_aColumnStyleNames.end(),"ORptExport::exportTableColumns: Section not found in m_aColumnStyleNames!");
     747           0 :     if ( aColFind == m_aColumnStyleNames.end() )
     748           0 :         return;
     749             : 
     750           0 :     TStringVec::iterator aColIter = aColFind->second.begin();
     751           0 :     TStringVec::iterator aColEnd = aColFind->second.end();
     752           0 :     for (; aColIter != aColEnd; ++aColIter)
     753             :     {
     754           0 :         AddAttribute( m_sTableStyle,*aColIter );
     755           0 :         SvXMLElementExport aColumn(*this,XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true);
     756           0 :     }
     757             : }
     758             : 
     759           0 : void ORptExport::exportContainer(const Reference< XSection>& _xSection)
     760             : {
     761             :     OSL_ENSURE(_xSection.is(),"Section is NULL -> GPF");
     762             : 
     763           0 :     exportTableColumns(_xSection);
     764             : 
     765           0 :     TSectionsGrid::iterator aFind = m_aSectionsGrid.find(_xSection.get());
     766             :     OSL_ENSURE(aFind != m_aSectionsGrid.end(),"ORptExport::exportContainer: Section not found in grid!");
     767           0 :     if ( aFind == m_aSectionsGrid.end() )
     768           0 :         return;
     769           0 :     TGrid::iterator aRowIter = aFind->second.begin();
     770           0 :     TGrid::iterator aRowEnd = aFind->second.end();
     771             : 
     772           0 :     sal_Int32 nEmptyCellColSpan = 0;
     773           0 :     TGridStyleMap::iterator aRowFind = m_aRowStyleNames.find(_xSection.get());
     774           0 :     TStringVec::iterator aHeightIter = aRowFind->second.begin();
     775             :     OSL_ENSURE(aRowFind->second.size() == aFind->second.size(),"Different count for rows");
     776             : 
     777           0 :     bool bShapeHandled = false;
     778           0 :     ::std::map<sal_Int32,sal_Int32> aRowSpan;
     779           0 :     for (sal_Int32 j = 0; aRowIter != aRowEnd; ++aRowIter,++j,++aHeightIter)
     780             :     {
     781           0 :         AddAttribute( m_sTableStyle,*aHeightIter );
     782           0 :         SvXMLElementExport aRow(*this,XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true);
     783           0 :         if ( aRowIter->first )
     784             :         {
     785           0 :             ::std::vector< TCell >::iterator aColIter = aRowIter->second.begin();
     786           0 :             ::std::vector< TCell >::iterator aColEnd = aRowIter->second.end();
     787           0 :             nEmptyCellColSpan = 0;
     788           0 :             for (; aColIter != aColEnd; ++aColIter)
     789             :             {
     790           0 :                 bool bCoveredCell = false;
     791           0 :                 sal_Int32 nColSpan = 0;
     792           0 :                 sal_Int32 nColIndex = aColIter - aRowIter->second.begin();
     793           0 :                 ::std::map<sal_Int32,sal_Int32>::iterator aRowSpanFind = aRowSpan.find(nColIndex);
     794           0 :                 if ( aRowSpanFind != aRowSpan.end() )
     795             :                 {
     796           0 :                     nColSpan = 1;
     797           0 :                     if ( !--(aRowSpanFind->second) )
     798           0 :                         aRowSpan.erase(aRowSpanFind);
     799             : 
     800           0 :                     if ( aColIter->nColSpan > 1 )
     801           0 :                         nColSpan += aColIter->nColSpan - 1;
     802             : 
     803           0 :                     bCoveredCell = true;
     804           0 :                     aColIter = aColIter + (aColIter->nColSpan - 1);
     805             :                 }
     806           0 :                 else if ( aColIter->bSet )
     807             :                 {
     808           0 :                     if ( nEmptyCellColSpan > 0 )
     809             :                     {
     810           0 :                         AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED,implConvertNumber(nEmptyCellColSpan) );
     811           0 :                         bCoveredCell = true;
     812           0 :                         nColSpan = nEmptyCellColSpan - 1;
     813           0 :                         nEmptyCellColSpan = 0;
     814             :                     }
     815           0 :                     sal_Int32 nSpan = aColIter->nColSpan;
     816           0 :                     if ( nSpan > 1 )
     817             :                     {
     818           0 :                         AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED,implConvertNumber(nSpan) );
     819           0 :                         nColSpan = nSpan - 1;
     820           0 :                         bCoveredCell = true;
     821             :                     }
     822           0 :                     nSpan = aColIter->nRowSpan;
     823           0 :                     if ( nSpan > 1 )
     824             :                     {
     825           0 :                         AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_ROWS_SPANNED,implConvertNumber(nSpan) );
     826           0 :                         aRowSpan[nColIndex] = nSpan - 1;
     827             :                     }
     828           0 :                     if ( aColIter->xElement.is() )
     829           0 :                         exportStyleName(aColIter->xElement.get(),GetAttrList(),m_sTableStyle);
     830             : 
     831             :                     // start <table:table-cell>
     832           0 :                     Reference<XFormattedField> xFormattedField(aColIter->xElement,uno::UNO_QUERY);
     833           0 :                     if ( xFormattedField.is() )
     834             :                     {
     835           0 :                         sal_Int32 nFormatKey = xFormattedField->getFormatKey();
     836           0 :                         XMLNumberFormatAttributesExportHelper aHelper(GetNumberFormatsSupplier(),*this);
     837           0 :                         bool bIsStandard = false;
     838           0 :                         OUString sEmpty;
     839           0 :                         sal_Int16 nCellType = aHelper.GetCellType(nFormatKey,bIsStandard);
     840             :                         // "Standard" means "no format set, value could be anything",
     841             :                         // so don't set a format attribute in this case.
     842             :                         // P.S.: "Standard" is called "General" in some languages
     843           0 :                         if (!bIsStandard)
     844             :                         {
     845           0 :                             if ( nCellType == util::NumberFormat::TEXT )
     846           0 :                                 aHelper.SetNumberFormatAttributes(sEmpty, sEmpty);
     847             :                             else
     848           0 :                                 aHelper.SetNumberFormatAttributes(nFormatKey, 0.0, false);
     849           0 :                         }
     850             :                     }
     851           0 :                     SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, false);
     852             : 
     853           0 :                     if ( aColIter->xElement.is() )
     854             :                     {
     855             :                         // start <text:p>
     856           0 :                         SvXMLElementExport aParagraphContent(*this,XML_NAMESPACE_TEXT, XML_P, true, false);
     857           0 :                         Reference<XServiceInfo> xElement(aColIter->xElement,uno::UNO_QUERY);
     858           0 :                         Reference<XReportComponent> xReportComponent = aColIter->xElement;
     859             : 
     860           0 :                         if ( !bShapeHandled )
     861             :                         {
     862           0 :                             bShapeHandled = true;
     863           0 :                             exportShapes(_xSection,false);
     864             :                         }
     865           0 :                         uno::Reference< XShape > xShape(xElement,uno::UNO_QUERY);
     866           0 :                         uno::Reference< XFixedLine > xFixedLine(xElement,uno::UNO_QUERY);
     867           0 :                         if ( !xShape.is() && !xFixedLine.is() )
     868             :                         {
     869           0 :                             Reference<XReportControlModel> xReportElement(xElement,uno::UNO_QUERY);
     870           0 :                             Reference<XReportDefinition> xReportDefinition(xElement,uno::UNO_QUERY);
     871           0 :                             Reference< XImageControl > xImage(xElement,uno::UNO_QUERY);
     872           0 :                             Reference<XSection> xSection(xElement,uno::UNO_QUERY);
     873             : 
     874           0 :                             XMLTokenEnum eToken = XML_SECTION;
     875           0 :                             bool bExportData = false;
     876           0 :                             if ( xElement->supportsService(SERVICE_FIXEDTEXT) )
     877             :                             {
     878           0 :                                 eToken = XML_FIXED_CONTENT;
     879             :                             }
     880           0 :                             else if ( xElement->supportsService(SERVICE_FORMATTEDFIELD) )
     881             :                             {
     882           0 :                                 eToken = XML_FORMATTED_TEXT;
     883           0 :                                 bExportData = true;
     884             :                             }
     885           0 :                             else if ( xElement->supportsService(SERVICE_IMAGECONTROL) )
     886             :                             {
     887           0 :                                 eToken = XML_IMAGE;
     888           0 :                                 OUString sTargetLocation = xImage->getImageURL();
     889           0 :                                 if ( !sTargetLocation.isEmpty() )
     890             :                                 {
     891           0 :                                     sTargetLocation = GetRelativeReference(sTargetLocation);
     892           0 :                                     AddAttribute(XML_NAMESPACE_FORM, XML_IMAGE_DATA,sTargetLocation);
     893             :                                 }
     894           0 :                                 bExportData = true;
     895           0 :                                 OUStringBuffer sValue;
     896           0 :                                 const SvXMLEnumMapEntry* aXML_ImageScaleEnumMap = OXMLHelper::GetImageScaleOptions();
     897           0 :                                 if ( SvXMLUnitConverter::convertEnum( sValue, xImage->getScaleMode(),aXML_ImageScaleEnumMap ) )
     898           0 :                                     AddAttribute(XML_NAMESPACE_REPORT, XML_SCALE, sValue.makeStringAndClear() );
     899             :                             }
     900           0 :                             else if ( xReportDefinition.is() )
     901             :                             {
     902           0 :                                 eToken = XML_SUB_DOCUMENT;
     903             :                             }
     904           0 :                             else if ( xSection.is() )
     905             :                             {
     906             :                             }
     907             : 
     908           0 :                             bool bPageSet = false;
     909           0 :                             if ( bExportData )
     910             :                             {
     911           0 :                                 bPageSet = exportFormula(XML_FORMULA,xReportElement->getDataField());
     912           0 :                                 if ( bPageSet )
     913           0 :                                     eToken = XML_FIXED_CONTENT;
     914           0 :                                 else if ( eToken == XML_IMAGE )
     915           0 :                                     AddAttribute(XML_NAMESPACE_REPORT, XML_PRESERVE_IRI, xImage->getPreserveIRI() ? XML_TRUE : XML_FALSE );
     916             :                             }
     917             : 
     918             :                             //if ( !bPageSet )
     919             :                             {
     920             :                                 // start <report:eToken>
     921           0 :                                 SvXMLElementExport aComponents(*this,XML_NAMESPACE_REPORT, eToken, false, false);
     922           0 :                                 if ( eToken == XML_FIXED_CONTENT )
     923           0 :                                     exportParagraph(xReportElement);
     924           0 :                                 if ( xReportElement.is() )
     925           0 :                                     exportReportElement(xReportElement);
     926             : 
     927           0 :                                 if ( eToken == XML_GROUP && xSection.is() )
     928           0 :                                     exportContainer(xSection);
     929           0 :                                 else if ( eToken == XML_SUB_DOCUMENT && xReportDefinition.is() )
     930             :                                 {
     931           0 :                                     SvXMLElementExport aOfficeElement( *this, XML_NAMESPACE_OFFICE, XML_BODY, true, true );
     932             :                                     SvXMLElementExport aElem( *this, true,
     933             :                                                             XML_NAMESPACE_OFFICE, XML_REPORT,
     934           0 :                                                               true, true );
     935             : 
     936           0 :                                     exportReportAttributes(xReportDefinition);
     937           0 :                                     exportReport(xReportDefinition);
     938             :                                 }
     939           0 :                                 else if ( xSection.is() )
     940           0 :                                     exportSection(xSection);
     941           0 :                             }
     942           0 :                         }
     943             :                     }
     944           0 :                     else if ( !bShapeHandled )
     945             :                     {
     946           0 :                         bShapeHandled = true;
     947           0 :                         exportShapes(_xSection);
     948             :                     }
     949           0 :                     aColIter = aColIter + (aColIter->nColSpan - 1);
     950             :                 }
     951             :                 else
     952           0 :                     ++nEmptyCellColSpan;
     953           0 :                 if ( bCoveredCell )
     954             :                 {
     955           0 :                     for (sal_Int32 k = 0; k < nColSpan; ++k)
     956             :                     {
     957           0 :                         SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true);
     958           0 :                     }
     959             : 
     960             :                 }
     961             :             }
     962           0 :             if ( nEmptyCellColSpan )
     963             :             {
     964             :                 {
     965           0 :                     AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED,implConvertNumber(nEmptyCellColSpan) );
     966           0 :                     SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
     967           0 :                     if ( !bShapeHandled )
     968             :                     {
     969           0 :                         bShapeHandled = true;
     970           0 :                         exportShapes(_xSection);
     971           0 :                     }
     972             :                 }
     973           0 :                 for (sal_Int32 k = 0; k < nEmptyCellColSpan; ++k)
     974             :                 {
     975           0 :                     SvXMLElementExport aCoveredCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true);
     976           0 :                 }
     977           0 :                 nEmptyCellColSpan = 0;
     978             :             }
     979             :         }
     980             :         else
     981             :         { // empty rows
     982           0 :             nEmptyCellColSpan = aRowIter->second.size();
     983           0 :             if ( nEmptyCellColSpan )
     984             :             {
     985             :                 {
     986           0 :                     AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED,implConvertNumber(nEmptyCellColSpan) );
     987           0 :                     SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
     988           0 :                     if ( !bShapeHandled )
     989             :                     {
     990           0 :                         bShapeHandled = true;
     991           0 :                         exportShapes(_xSection);
     992           0 :                     }
     993             :                 }
     994           0 :                 for (sal_Int32 k = 1; k < nEmptyCellColSpan; ++k)
     995             :                 {
     996           0 :                     SvXMLElementExport aCoveredCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true);
     997           0 :                 }
     998           0 :                 nEmptyCellColSpan = 0;
     999             :             }
    1000             :         }
    1001           0 :     }
    1002             : }
    1003             : 
    1004           0 : OUString ORptExport::convertFormula(const OUString& _sFormula)
    1005             : {
    1006           0 :     OUString sFormula = _sFormula;
    1007           0 :     if ( _sFormula == "rpt:" )
    1008           0 :         sFormula = "";
    1009           0 :     return sFormula;
    1010             : }
    1011             : 
    1012           0 : bool ORptExport::exportFormula(enum ::xmloff::token::XMLTokenEnum eName,const OUString& _sFormula)
    1013             : {
    1014           0 :     const OUString sFieldData = convertFormula(_sFormula);
    1015           0 :     static const OUString s_sPageNumber("PageNumber()");
    1016           0 :     static const OUString s_sPageCount("PageCount()");
    1017           0 :     sal_Int32 nPageNumberIndex = sFieldData.indexOf(s_sPageNumber);
    1018           0 :     sal_Int32 nPageCountIndex = sFieldData.indexOf(s_sPageCount);
    1019           0 :     bool bRet = nPageNumberIndex != -1 || nPageCountIndex != -1;
    1020           0 :     if ( !bRet )
    1021           0 :         AddAttribute(XML_NAMESPACE_REPORT, eName,sFieldData);
    1022             : 
    1023           0 :     return bRet;
    1024             : }
    1025             : 
    1026           0 : void ORptExport::exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt,const OUString& _sName)
    1027             : {
    1028           0 :     Reference<XPropertySet> xFind(_xProp);
    1029           0 :     TPropertyStyleMap::iterator aFind = m_aAutoStyleNames.find(xFind);
    1030           0 :     if ( aFind != m_aAutoStyleNames.end() )
    1031             :     {
    1032             :         _rAtt.AddAttribute( _sName,
    1033           0 :                             aFind->second );
    1034           0 :         m_aAutoStyleNames.erase(aFind);
    1035           0 :     }
    1036           0 : }
    1037             : 
    1038           0 : bool ORptExport::exportGroup(const Reference<XReportDefinition>& _xReportDefinition,sal_Int32 _nPos,bool _bExportAutoStyle)
    1039             : {
    1040           0 :     bool bGroupExported = false;
    1041           0 :     if ( _xReportDefinition.is() )
    1042             :     {
    1043           0 :         Reference< XGroups > xGroups = _xReportDefinition->getGroups();
    1044           0 :         if ( xGroups.is() )
    1045             :         {
    1046           0 :             sal_Int32 nCount = xGroups->getCount();
    1047           0 :             if ( _nPos >= 0 && _nPos < nCount )
    1048             :             {
    1049           0 :                 bGroupExported = true;
    1050           0 :                 Reference<XGroup> xGroup(xGroups->getByIndex(_nPos),uno::UNO_QUERY);
    1051             :                 OSL_ENSURE(xGroup.is(),"No Group prepare for GPF");
    1052           0 :                 if ( _bExportAutoStyle )
    1053             :                 {
    1054           0 :                     if ( xGroup->getHeaderOn() )
    1055           0 :                         exportSectionAutoStyle(xGroup->getHeader());
    1056           0 :                     exportGroup(_xReportDefinition,_nPos+1,_bExportAutoStyle);
    1057           0 :                     if ( xGroup->getFooterOn() )
    1058           0 :                         exportSectionAutoStyle(xGroup->getFooter());
    1059             :                 }
    1060             :                 else
    1061             :                 {
    1062           0 :                     if ( xGroup->getSortAscending() )
    1063           0 :                         AddAttribute(XML_NAMESPACE_REPORT, XML_SORT_ASCENDING, XML_TRUE );
    1064             : 
    1065           0 :                     if ( xGroup->getStartNewColumn() )
    1066           0 :                         AddAttribute(XML_NAMESPACE_REPORT, XML_START_NEW_COLUMN, XML_TRUE);
    1067           0 :                     if ( xGroup->getResetPageNumber() )
    1068           0 :                         AddAttribute(XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER, XML_TRUE );
    1069             : 
    1070           0 :                     const OUString sField = xGroup->getExpression();
    1071           0 :                     OUString sExpression  = sField;
    1072           0 :                     if ( !sExpression.isEmpty() )
    1073             :                     {
    1074           0 :                         static OUString s_sQuote("\"\"");
    1075           0 :                         sal_Int32 nIndex = sExpression.indexOf('"');
    1076           0 :                         while ( nIndex > -1 )
    1077             :                         {
    1078           0 :                             sExpression = sExpression.replaceAt(nIndex,1,s_sQuote);
    1079           0 :                             nIndex = sExpression.indexOf('"',nIndex+2);
    1080             :                         }
    1081           0 :                         OUString sFormula("rpt:HASCHANGED(\"");
    1082             : 
    1083           0 :                         TGroupFunctionMap::iterator aGroupFind = m_aGroupFunctionMap.find(xGroup);
    1084           0 :                         if ( aGroupFind != m_aGroupFunctionMap.end() )
    1085           0 :                             sExpression = aGroupFind->second->getName();
    1086           0 :                         sFormula += sExpression;
    1087           0 :                         sFormula += "\")";
    1088           0 :                         sExpression = sFormula;
    1089             :                     }
    1090           0 :                     AddAttribute(XML_NAMESPACE_REPORT, XML_SORT_EXPRESSION, sField);
    1091           0 :                     AddAttribute(XML_NAMESPACE_REPORT, XML_GROUP_EXPRESSION,sExpression);
    1092           0 :                     sal_Int16 nRet = xGroup->getKeepTogether();
    1093           0 :                     OUStringBuffer sValue;
    1094           0 :                     const SvXMLEnumMapEntry* aXML_KeepTogetherEnumMap = OXMLHelper::GetKeepTogetherOptions();
    1095           0 :                     if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_KeepTogetherEnumMap ) )
    1096           0 :                         AddAttribute(XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER,sValue.makeStringAndClear());
    1097             : 
    1098           0 :                     SvXMLElementExport aGroup(*this,XML_NAMESPACE_REPORT, XML_GROUP, true, true);
    1099           0 :                     exportFunctions(xGroup->getFunctions().get());
    1100           0 :                     if ( xGroup->getHeaderOn() )
    1101             :                     {
    1102           0 :                         Reference<XSection> xSection = xGroup->getHeader();
    1103           0 :                         if ( xSection->getRepeatSection() )
    1104           0 :                             AddAttribute(XML_NAMESPACE_REPORT, XML_REPEAT_SECTION,XML_TRUE );
    1105           0 :                         SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_GROUP_HEADER, true, true);
    1106           0 :                         exportSection(xSection);
    1107             :                     }
    1108           0 :                     exportGroup(_xReportDefinition,_nPos+1,_bExportAutoStyle);
    1109           0 :                     if ( xGroup->getFooterOn() )
    1110             :                     {
    1111           0 :                         Reference<XSection> xSection = xGroup->getFooter();
    1112           0 :                         if ( xSection->getRepeatSection() )
    1113           0 :                             AddAttribute(XML_NAMESPACE_REPORT, XML_REPEAT_SECTION,XML_TRUE );
    1114           0 :                         SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_GROUP_FOOTER, true, true);
    1115           0 :                         exportSection(xSection);
    1116           0 :                     }
    1117           0 :                 }
    1118             :             }
    1119           0 :             else if ( _bExportAutoStyle )
    1120             :             {
    1121           0 :                 exportSectionAutoStyle(_xReportDefinition->getDetail());
    1122             :             }
    1123             :             else
    1124             :             {
    1125           0 :                 SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_DETAIL, true, true);
    1126           0 :                 exportSection(_xReportDefinition->getDetail());
    1127             :             }
    1128           0 :         }
    1129             :     }
    1130           0 :     return bGroupExported;
    1131             : }
    1132             : 
    1133           0 : void ORptExport::exportAutoStyle(XPropertySet* _xProp,const Reference<XFormattedField>& _xParentFormattedField)
    1134             : {
    1135           0 :     const uno::Reference<report::XReportControlFormat> xFormat(_xProp,uno::UNO_QUERY);
    1136           0 :     if ( xFormat.is() )
    1137             :     {
    1138             :         try
    1139             :         {
    1140           0 :             const awt::FontDescriptor aFont = xFormat->getFontDescriptor();
    1141             :             OSL_ENSURE(!aFont.Name.isEmpty(),"No Font Name !");
    1142             :             GetFontAutoStylePool()->Add(aFont.Name,aFont.StyleName,static_cast<FontFamily>(aFont.Family),
    1143           0 :                 static_cast<FontPitch>(aFont.Pitch),aFont.CharSet );
    1144             :         }
    1145           0 :         catch(beans::UnknownPropertyException&)
    1146             :         {
    1147             :             // not interested in
    1148             :         }
    1149             :     }
    1150           0 :     const uno::Reference< report::XShape> xShape(_xProp,uno::UNO_QUERY);
    1151           0 :     if ( xShape.is() )
    1152             :     {
    1153           0 :         ::std::vector< XMLPropertyState > aPropertyStates( m_xParaPropMapper->Filter(_xProp) );
    1154           0 :         if ( !aPropertyStates.empty() )
    1155           0 :             m_aAutoStyleNames.insert( TPropertyStyleMap::value_type(_xProp,GetAutoStylePool()->Add( XML_STYLE_FAMILY_TEXT_PARAGRAPH, aPropertyStates )));
    1156             :     }
    1157           0 :     ::std::vector< XMLPropertyState > aPropertyStates( m_xCellStylesExportPropertySetMapper->Filter(_xProp) );
    1158           0 :     Reference<XFixedLine> xFixedLine(_xProp,uno::UNO_QUERY);
    1159           0 :     if ( xFixedLine.is() )
    1160             :     {
    1161           0 :         uno::Reference<beans::XPropertySet> xBorderProp = OXMLHelper::createBorderPropertySet();
    1162           0 :         table::BorderLine2 aValue;
    1163           0 :         aValue.Color = COL_BLACK;
    1164           0 :         aValue.InnerLineWidth = aValue.LineDistance = 0;
    1165           0 :         aValue.OuterLineWidth = 2;
    1166           0 :         aValue.LineStyle = table::BorderLineStyle::SOLID;
    1167           0 :         aValue.LineWidth = 2;
    1168             : 
    1169           0 :         awt::Point aPos = xFixedLine->getPosition();
    1170           0 :         awt::Size aSize = xFixedLine->getSize();
    1171           0 :         sal_Int32 nSectionHeight = xFixedLine->getSection()->getHeight();
    1172             : 
    1173           0 :         OUString sBorderProp;
    1174           0 :         ::std::vector< OUString> aProps;
    1175           0 :         if ( xFixedLine->getOrientation() == 1 ) // vertical
    1176             :         {
    1177             :             // check if border should be left
    1178           0 :             if ( !aPos.X )
    1179             :             {
    1180           0 :                 sBorderProp = PROPERTY_BORDERLEFT;
    1181           0 :                 aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERRIGHT));
    1182             :             }
    1183             :             else
    1184             :             {
    1185           0 :                 sBorderProp = PROPERTY_BORDERRIGHT;
    1186           0 :                 aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERLEFT));
    1187             :             }
    1188           0 :             aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERTOP));
    1189           0 :             aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERBOTTOM));
    1190             :         }
    1191             :         else // horizontal
    1192             :         {
    1193             :             // check if border should be bottom
    1194           0 :             if ( (aPos.Y + aSize.Height) == nSectionHeight )
    1195             :             {
    1196           0 :                 sBorderProp = PROPERTY_BORDERBOTTOM;
    1197           0 :                 aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERTOP));
    1198             :             }
    1199             :             else
    1200             :             {
    1201           0 :                 sBorderProp = PROPERTY_BORDERTOP;
    1202           0 :                 aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERBOTTOM));
    1203             :             }
    1204           0 :             aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERRIGHT));
    1205           0 :             aProps.push_back(static_cast<const OUString&>(PROPERTY_BORDERLEFT));
    1206             :         }
    1207             : 
    1208           0 :         xBorderProp->setPropertyValue(sBorderProp,uno::makeAny(aValue));
    1209             : 
    1210           0 :         aValue.Color = aValue.OuterLineWidth = aValue.LineWidth = 0;
    1211           0 :         aValue.LineStyle = table::BorderLineStyle::NONE;
    1212           0 :         uno::Any aEmpty;
    1213           0 :         aEmpty <<= aValue;
    1214             :         ::std::for_each(aProps.begin(),aProps.end(),
    1215           0 :             ::boost::bind(&beans::XPropertySet::setPropertyValue,xBorderProp,_1,aEmpty));
    1216             : 
    1217           0 :         ::std::vector< XMLPropertyState > aBorderStates(m_xCellStylesExportPropertySetMapper->Filter(xBorderProp));
    1218           0 :         ::std::copy(aBorderStates.begin(),aBorderStates.end(),::std::back_inserter(aPropertyStates));
    1219             :     }
    1220             :     else
    1221             :     {
    1222           0 :         const Reference<XFormattedField> xFormattedField(_xProp,uno::UNO_QUERY);
    1223           0 :         if ( (_xParentFormattedField.is() || xFormattedField.is()) && !aPropertyStates.empty() )
    1224             :         {
    1225           0 :             sal_Int32 nNumberFormat = 0;
    1226           0 :             if ( _xParentFormattedField.is() )
    1227           0 :                 nNumberFormat = _xParentFormattedField->getFormatKey();
    1228             :             else
    1229           0 :                 nNumberFormat = xFormattedField->getFormatKey();
    1230             :             {
    1231           0 :                 sal_Int32 nStyleMapIndex = m_xCellStylesExportPropertySetMapper->getPropertySetMapper()->FindEntryIndex( CTF_RPT_NUMBERFORMAT );
    1232           0 :                 addDataStyle(nNumberFormat);
    1233           0 :                 XMLPropertyState aNumberStyleState( nStyleMapIndex, uno::makeAny( getDataStyleName(nNumberFormat) ) );
    1234           0 :                 aPropertyStates.push_back( aNumberStyleState );
    1235             :             }
    1236           0 :         }
    1237             :     }
    1238             : 
    1239           0 :     if ( !aPropertyStates.empty() )
    1240           0 :         m_aAutoStyleNames.insert( TPropertyStyleMap::value_type(_xProp,GetAutoStylePool()->Add( XML_STYLE_FAMILY_TABLE_CELL, aPropertyStates )));
    1241           0 : }
    1242             : 
    1243           0 : void ORptExport::exportAutoStyle(const Reference<XSection>& _xProp)
    1244             : {
    1245           0 :     ::std::vector< XMLPropertyState > aPropertyStates( m_xTableStylesExportPropertySetMapper->Filter(_xProp.get()) );
    1246           0 :     if ( !aPropertyStates.empty() )
    1247           0 :         m_aAutoStyleNames.insert( TPropertyStyleMap::value_type(_xProp.get(),GetAutoStylePool()->Add( XML_STYLE_FAMILY_TABLE_TABLE, aPropertyStates )));
    1248           0 : }
    1249             : 
    1250           0 : void ORptExport::SetBodyAttributes()
    1251             : {
    1252           0 :     Reference<XReportDefinition> xProp(getReportDefinition());
    1253           0 :     exportReportAttributes(xProp);
    1254           0 : }
    1255             : 
    1256           0 : void ORptExport::exportReportAttributes(const Reference<XReportDefinition>& _xReport)
    1257             : {
    1258           0 :     if ( _xReport.is() )
    1259             :     {
    1260           0 :         OUStringBuffer sValue;
    1261           0 :         const SvXMLEnumMapEntry* aXML_CommnadTypeEnumMap = OXMLHelper::GetCommandTypeOptions();
    1262           0 :         if ( SvXMLUnitConverter::convertEnum( sValue, static_cast<sal_uInt16>(_xReport->getCommandType()),aXML_CommnadTypeEnumMap ) )
    1263           0 :             AddAttribute(XML_NAMESPACE_REPORT, XML_COMMAND_TYPE,sValue.makeStringAndClear());
    1264             : 
    1265           0 :         OUString sComamnd = _xReport->getCommand();
    1266           0 :         if ( !sComamnd.isEmpty() )
    1267           0 :             AddAttribute(XML_NAMESPACE_REPORT, XML_COMMAND, sComamnd);
    1268             : 
    1269           0 :         OUString sFilter( _xReport->getFilter() );
    1270           0 :         if ( !sFilter.isEmpty() )
    1271           0 :             AddAttribute( XML_NAMESPACE_REPORT, XML_FILTER, sFilter );
    1272             : 
    1273           0 :         AddAttribute(XML_NAMESPACE_OFFICE, XML_MIMETYPE,_xReport->getMimeType());
    1274             : 
    1275           0 :         bool bEscapeProcessing( _xReport->getEscapeProcessing() );
    1276           0 :         if ( !bEscapeProcessing )
    1277           0 :             AddAttribute( XML_NAMESPACE_REPORT, XML_ESCAPE_PROCESSING, ::xmloff::token::GetXMLToken( XML_FALSE ) );
    1278             : 
    1279           0 :         OUString sName = _xReport->getCaption();
    1280           0 :         if ( !sName.isEmpty() )
    1281           0 :             AddAttribute(XML_NAMESPACE_OFFICE, XML_CAPTION,sName);
    1282           0 :         sName = _xReport->getName();
    1283           0 :         if ( !sName.isEmpty() )
    1284           0 :             AddAttribute(XML_NAMESPACE_DRAW, XML_NAME,sName);
    1285             :     }
    1286           0 : }
    1287             : 
    1288           0 : void ORptExport::_ExportContent()
    1289             : {
    1290           0 :     exportReport(getReportDefinition());
    1291           0 : }
    1292             : 
    1293           0 : void ORptExport::_ExportMasterStyles()
    1294             : {
    1295           0 :     GetPageExport()->exportMasterStyles( true );
    1296           0 : }
    1297             : 
    1298           0 : void ORptExport::collectComponentStyles()
    1299             : {
    1300           0 :     if ( m_bAllreadyFilled )
    1301           0 :         return;
    1302             : 
    1303           0 :     m_bAllreadyFilled = true;
    1304           0 :     Reference<XReportDefinition> xProp(getReportDefinition());
    1305           0 :     if ( xProp.is() )
    1306             :     {
    1307           0 :         uno::Reference< report::XSection> xParent(xProp->getParent(),uno::UNO_QUERY);
    1308           0 :         if ( xParent.is() )
    1309           0 :             exportAutoStyle(xProp.get());
    1310             : 
    1311           0 :         if ( xProp->getReportHeaderOn() )
    1312           0 :             exportSectionAutoStyle(xProp->getReportHeader());
    1313           0 :         if ( xProp->getPageHeaderOn() )
    1314           0 :             exportSectionAutoStyle(xProp->getPageHeader());
    1315             : 
    1316           0 :         exportGroup(xProp,0,true);
    1317             : 
    1318           0 :         if ( xProp->getPageFooterOn() )
    1319           0 :             exportSectionAutoStyle(xProp->getPageFooter());
    1320           0 :         if ( xProp->getReportFooterOn() )
    1321           0 :             exportSectionAutoStyle(xProp->getReportFooter());
    1322           0 :     }
    1323             : }
    1324             : 
    1325           0 : void ORptExport::_ExportAutoStyles()
    1326             : {
    1327             :     // there are no styles that require their own autostyles
    1328           0 :     if ( getExportFlags() & EXPORT_CONTENT )
    1329             :     {
    1330           0 :         collectComponentStyles();
    1331             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_TABLE
    1332           0 :                                         ,GetDocHandler()
    1333           0 :                                         ,GetMM100UnitConverter()
    1334           0 :                                         ,GetNamespaceMap()
    1335           0 :         );
    1336             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_COLUMN
    1337           0 :                                         ,GetDocHandler()
    1338           0 :                                         ,GetMM100UnitConverter()
    1339           0 :                                         ,GetNamespaceMap()
    1340           0 :         );
    1341             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_ROW
    1342           0 :                                         ,GetDocHandler()
    1343           0 :                                         ,GetMM100UnitConverter()
    1344           0 :                                         ,GetNamespaceMap()
    1345           0 :         );
    1346             : 
    1347             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_CELL
    1348           0 :                                         ,GetDocHandler()
    1349           0 :                                         ,GetMM100UnitConverter()
    1350           0 :                                         ,GetNamespaceMap()
    1351           0 :         );
    1352             : 
    1353           0 :         exportDataStyles();
    1354           0 :         GetShapeExport()->exportAutoStyles();
    1355             :     }
    1356             :     // exported in _ExportMasterStyles
    1357           0 :     if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
    1358           0 :         GetPageExport()->collectAutoStyles( false );
    1359           0 :     if( (getExportFlags() & EXPORT_MASTERSTYLES) != 0 )
    1360           0 :         GetPageExport()->exportAutoStyles();
    1361           0 : }
    1362             : 
    1363           0 : void ORptExport::_ExportStyles(bool bUsed)
    1364             : {
    1365           0 :     SvXMLExport::_ExportStyles(bUsed);
    1366             : 
    1367             :     // write draw:style-name for object graphic-styles
    1368           0 :     GetShapeExport()->ExportGraphicDefaults();
    1369           0 : }
    1370             : 
    1371           0 : sal_uInt32 ORptExport::exportDoc(enum ::xmloff::token::XMLTokenEnum eClass)
    1372             : {
    1373           0 :     return SvXMLExport::exportDoc( eClass );
    1374             : }
    1375             : 
    1376           0 : OUString ORptExport::implConvertNumber(sal_Int32 _nValue)
    1377             : {
    1378           0 :     OUStringBuffer aBuffer;
    1379           0 :     ::sax::Converter::convertNumber(aBuffer, _nValue);
    1380           0 :     return aBuffer.makeStringAndClear();
    1381             : }
    1382             : 
    1383             : 
    1384           0 : SvXMLAutoStylePoolP* ORptExport::CreateAutoStylePool()
    1385             : {
    1386           0 :     return new OXMLAutoStylePoolP(*this);
    1387             : }
    1388             : 
    1389           0 : void SAL_CALL ORptExport::setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException, std::exception)
    1390             : {
    1391           0 :     m_xReportDefinition.set(xDoc,UNO_QUERY_THROW);
    1392             :     OSL_ENSURE(m_xReportDefinition.is(),"DataSource is NULL!");
    1393             : 
    1394           0 :     SvXMLExport::setSourceDocument(xDoc);
    1395           0 : }
    1396             : 
    1397           0 : void ORptExport::_ExportFontDecls()
    1398             : {
    1399           0 :     GetFontAutoStylePool(); // make sure the pool is created
    1400           0 :     collectComponentStyles();
    1401           0 :     SvXMLExport::_ExportFontDecls();
    1402           0 : }
    1403             : 
    1404           0 : void ORptExport::exportParagraph(const Reference< XReportControlModel >& _xReportElement)
    1405             : {
    1406             :     OSL_PRECOND(_xReportElement.is(),"Element is null!");
    1407             :     // start <text:p>
    1408           0 :     SvXMLElementExport aParagraphContent(*this,XML_NAMESPACE_TEXT, XML_P, false, false);
    1409           0 :     if ( Reference<XFormattedField>(_xReportElement,uno::UNO_QUERY).is() )
    1410             :     {
    1411           0 :         OUString sFieldData = _xReportElement->getDataField();
    1412           0 :         static const OUString s_sPageNumber("PageNumber()");
    1413           0 :         static const OUString s_sPageCount("PageCount()");
    1414           0 :         static const OUString s_sReportPrefix("rpt:");
    1415           0 :         sFieldData = sFieldData.copy(s_sReportPrefix.getLength(),sFieldData.getLength() - s_sReportPrefix.getLength());
    1416           0 :         sal_Int32 nPageNumberIndex = sFieldData.indexOf(s_sPageNumber);
    1417           0 :         if ( nPageNumberIndex != -1 )
    1418             :         {
    1419           0 :             sal_Int32 nIndex = 0;
    1420           0 :             do
    1421             :             {
    1422           0 :                 OUString sToken = sFieldData.getToken( 0, '&', nIndex );
    1423           0 :                 sToken = sToken.trim();
    1424           0 :                 if ( !sToken.isEmpty() )
    1425             :                 {
    1426           0 :                     if ( sToken == s_sPageNumber )
    1427             :                     {
    1428           0 :                         static const OUString s_sCurrent("current");
    1429           0 :                         AddAttribute(XML_NAMESPACE_TEXT, XML_SELECT_PAGE, s_sCurrent );
    1430           0 :                         SvXMLElementExport aPageNumber(*this,XML_NAMESPACE_TEXT, XML_PAGE_NUMBER, false, false);
    1431           0 :                         Characters(OUString("1"));
    1432             :                     }
    1433           0 :                     else if ( sToken == s_sPageCount )
    1434             :                     {
    1435           0 :                         SvXMLElementExport aPageNumber(*this,XML_NAMESPACE_TEXT, XML_PAGE_COUNT, false, false);
    1436           0 :                         Characters(OUString("1"));
    1437             :                     }
    1438             :                     else
    1439             :                     {
    1440             : 
    1441           0 :                         if ( sToken.startsWith("\"") && sToken.endsWith("\"") )
    1442           0 :                             sToken = sToken.copy(1,sToken.getLength()-2);
    1443             : 
    1444           0 :                         bool bPrevCharIsSpace = false;
    1445           0 :                         GetTextParagraphExport()->exportText(sToken,bPrevCharIsSpace);
    1446             :                     }
    1447           0 :                 }
    1448             :             }
    1449           0 :             while ( nIndex >= 0 );
    1450           0 :         }
    1451             :     }
    1452           0 :     Reference< XFixedText > xFT(_xReportElement,UNO_QUERY);
    1453           0 :     if ( xFT.is() )
    1454             :     {
    1455           0 :         OUString sExpr = xFT->getLabel();
    1456           0 :         bool bPrevCharIsSpace = false;
    1457           0 :         GetTextParagraphExport()->exportText(sExpr,bPrevCharIsSpace);
    1458           0 :     }
    1459           0 : }
    1460             : 
    1461           0 : XMLShapeExport* ORptExport::CreateShapeExport()
    1462             : {
    1463           0 :     XMLShapeExport* pShapeExport = new XMLShapeExport( *this, XMLTextParagraphExport::CreateShapeExtPropMapper( *this ) );
    1464           0 :     return pShapeExport;
    1465             : }
    1466             : 
    1467           0 : void ORptExport::exportShapes(const Reference< XSection>& _xSection,bool _bAddParagraph)
    1468             : {
    1469           0 :     rtl::Reference< XMLShapeExport > xShapeExport = GetShapeExport();
    1470           0 :     xShapeExport->seekShapes(_xSection.get());
    1471           0 :     const sal_Int32 nCount = _xSection->getCount();
    1472           0 :     ::std::unique_ptr<SvXMLElementExport> pParagraphContent;
    1473           0 :     if ( _bAddParagraph )
    1474           0 :         pParagraphContent.reset(new SvXMLElementExport(*this,XML_NAMESPACE_TEXT, XML_P, true, false));
    1475             : 
    1476           0 :     awt::Point aRefPoint;
    1477           0 :     aRefPoint.X = rptui::getStyleProperty<sal_Int32>(_xSection->getReportDefinition(),PROPERTY_LEFTMARGIN);
    1478           0 :     for (sal_Int32 i = 0; i < nCount; ++i)
    1479             :     {
    1480           0 :         uno::Reference< XShape > xShape(_xSection->getByIndex(i),uno::UNO_QUERY);
    1481           0 :         if ( xShape.is() )
    1482             :         {
    1483           0 :             ::std::unique_ptr<SvXMLElementExport> pSubDocument;
    1484           0 :             uno::Reference< frame::XModel> xModel(xShape->getPropertyValue("Model"),uno::UNO_QUERY);
    1485           0 :             if ( xModel.is() ) // special handling for chart object
    1486             :             {
    1487           0 :                 pSubDocument.reset(new SvXMLElementExport(*this,XML_NAMESPACE_REPORT, XML_SUB_DOCUMENT, false, false));
    1488           0 :                 exportMasterDetailFields(xShape.get());
    1489           0 :                 exportReportElement(xShape.get());
    1490             :             }
    1491             : 
    1492           0 :             AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, XML_PARAGRAPH );
    1493           0 :             xShapeExport->exportShape(xShape.get(),SEF_DEFAULT|SEF_EXPORT_NO_WS,&aRefPoint);
    1494             :         }
    1495           0 :     }
    1496           0 : }
    1497             : 
    1498           0 : void ORptExport::exportGroupsExpressionAsFunction(const Reference< XGroups>& _xGroups)
    1499             : {
    1500           0 :     if ( _xGroups.is() )
    1501             :     {
    1502           0 :         uno::Reference< XFunctions> xFunctions = _xGroups->getReportDefinition()->getFunctions();
    1503           0 :         const sal_Int32 nCount = _xGroups->getCount();
    1504           0 :         for (sal_Int32 i = 0; i < nCount; ++i)
    1505             :         {
    1506           0 :             uno::Reference< XGroup> xGroup(_xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
    1507           0 :             const ::sal_Int16 nGroupOn = xGroup->getGroupOn();
    1508           0 :             if ( nGroupOn != report::GroupOn::DEFAULT )
    1509             :             {
    1510           0 :                 uno::Reference< XFunction> xFunction = xFunctions->createFunction();
    1511           0 :                 OUString sFunction,sPrefix,sPostfix;
    1512           0 :                 OUString sExpression = xGroup->getExpression();
    1513           0 :                 OUString sFunctionName;
    1514           0 :                 OUString sInitialFormula;
    1515           0 :                 switch(nGroupOn)
    1516             :                 {
    1517             :                     case report::GroupOn::PREFIX_CHARACTERS:
    1518           0 :                         sFunction = "LEFT";
    1519           0 :                         sPrefix = ";" + OUString::number(xGroup->getGroupInterval());
    1520           0 :                         break;
    1521             :                     case report::GroupOn::YEAR:
    1522           0 :                         sFunction = "YEAR";
    1523           0 :                         break;
    1524             :                     case report::GroupOn::QUARTAL:
    1525           0 :                         sFunction   = "INT((MONTH";
    1526           0 :                         sPostfix    = "-1)/3)+1";
    1527           0 :                         sFunctionName = "QUARTAL_" + sExpression;
    1528           0 :                         break;
    1529             :                     case report::GroupOn::MONTH:
    1530           0 :                         sFunction = "MONTH";
    1531           0 :                         break;
    1532             :                     case report::GroupOn::WEEK:
    1533           0 :                         sFunction = "WEEK";
    1534           0 :                         break;
    1535             :                     case report::GroupOn::DAY:
    1536           0 :                         sFunction = "DAY";
    1537           0 :                         break;
    1538             :                     case report::GroupOn::HOUR:
    1539           0 :                         sFunction = "HOUR";
    1540           0 :                         break;
    1541             :                     case report::GroupOn::MINUTE:
    1542           0 :                         sFunction = "MINUTE";
    1543           0 :                         break;
    1544             :                     case report::GroupOn::INTERVAL:
    1545             :                         {
    1546           0 :                             sFunction = "INT";
    1547           0 :                             uno::Reference< XFunction> xCountFunction = xFunctions->createFunction();
    1548           0 :                             xCountFunction->setInitialFormula(beans::Optional< OUString>(sal_True,OUString("rpt:0")));
    1549           0 :                             OUString sCountName = sFunction + "_count_" + sExpression;
    1550           0 :                             xCountFunction->setName(sCountName);
    1551           0 :                             xCountFunction->setFormula( "rpt:[" + sCountName + "] + 1" );
    1552           0 :                             exportFunction(xCountFunction);
    1553           0 :                             sExpression = sCountName;
    1554             :                             // The reference to sCountName in the formula of sFunctionName refers to the *old* value
    1555             :                             // so we need to expand the the formula of sCountName
    1556           0 :                             sPrefix = " + 1) / " + OUString::number(xGroup->getGroupInterval());
    1557           0 :                             sFunctionName = sFunction + "_" + sExpression;
    1558           0 :                             sFunction = sFunction + "(";
    1559           0 :                             sInitialFormula = "rpt:0";
    1560             :                         }
    1561           0 :                         break;
    1562             :                     default:
    1563             :                         ;
    1564             :                 }
    1565           0 :                 if ( sFunctionName.isEmpty() )
    1566           0 :                     sFunctionName = sFunction + "_" + sExpression;
    1567           0 :                 if ( !sFunction.isEmpty() )
    1568             :                 {
    1569           0 :                     sal_Unicode pReplaceChars[] = { '(',')',';',',','+','-','[',']','/','*'};
    1570           0 :                     for(sal_uInt32 j= 0; j < sizeof(pReplaceChars)/sizeof(pReplaceChars[0]);++j)
    1571           0 :                         sFunctionName = sFunctionName.replace(pReplaceChars[j],'_');
    1572             : 
    1573           0 :                     xFunction->setName(sFunctionName);
    1574           0 :                     if ( !sInitialFormula.isEmpty() )
    1575           0 :                         xFunction->setInitialFormula(beans::Optional< OUString>(sal_True, sInitialFormula));
    1576           0 :                     sFunction = "rpt:" + sFunction;
    1577           0 :                     sFunction += "([";
    1578           0 :                     sFunction += sExpression;
    1579           0 :                     sFunction += "]";
    1580             : 
    1581           0 :                     if ( !sPrefix.isEmpty() )
    1582           0 :                         sFunction += sPrefix;
    1583           0 :                     sFunction += ")";
    1584           0 :                     if ( !sPostfix.isEmpty() )
    1585           0 :                         sFunction += sPostfix;
    1586           0 :                     xFunction->setFormula(sFunction);
    1587           0 :                     exportFunction(xFunction);
    1588           0 :                     m_aGroupFunctionMap.insert(TGroupFunctionMap::value_type(xGroup,xFunction));
    1589           0 :                 }
    1590             :             }
    1591           0 :         }
    1592             :     }
    1593           0 : }
    1594             : 
    1595             : 
    1596           0 : }// rptxml
    1597             : 
    1598             : 
    1599             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10