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