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