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