LibreOffice Module reportdesign (master)  1
xmlSubDocument.cxx
Go to the documentation of this file.
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 #include "xmlSubDocument.hxx"
20 #include "xmlCell.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnamespace.hxx>
25 #include "xmlEnums.hxx"
26 #include "xmlMasterFields.hxx"
27 #include "xmlTable.hxx"
28 #include <comphelper/property.hxx>
29 #include <com/sun/star/report/XReportControlModel.hpp>
30 #include <sal/log.hxx>
31 #include <osl/diagnose.h>
32 
33 namespace rptxml
34 {
35  using namespace ::com::sun::star;
36  using namespace ::com::sun::star::report;
37  using namespace ::com::sun::star::uno;
38  using namespace ::com::sun::star::xml::sax;
39 
40 OXMLSubDocument::OXMLSubDocument( ORptFilter& rImport
41  ,const Reference< XReportComponent > & _xComponent
42  ,OXMLTable* _pContainer
43  ,OXMLCell* _pCellParent) :
44  OXMLReportElementBase( rImport,_xComponent,_pContainer)
45 ,m_xFake(_xComponent)
46 ,m_pCellParent(_pCellParent)
47 ,m_nCurrentCount(0)
48 ,m_bContainsShape(false)
49 {
50 
51 }
52 
54 {
55 }
56 
57 css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLSubDocument::createFastChildContext(
58  sal_Int32 nElement,
59  const Reference< XFastAttributeList > & xAttrList )
60 {
61  css::uno::Reference< css::xml::sax::XFastContextHandler > xContext = OXMLReportElementBase::createFastChildContext(nElement,xAttrList);
62  if (xContext)
63  return xContext;
64 
65  switch( nElement )
66  {
68  {
70  xContext = new OXMLMasterFields(static_cast<ORptFilter&>(GetImport()),xAttrList ,this);
71  }
72  break;
73  // FIXME: is it *intentional* that this is supported?
74  // ORptExport::exportContainer() can export this but the import
75  // used to be rather accidental previously
77  xContext = new RptXMLDocumentBodyContext(GetImport());
78  break;
79 
80  case XML_ELEMENT(DRAW, XML_FRAME):
81  {
82  if ( !m_bContainsShape )
83  m_nCurrentCount = m_pContainer->getSection()->getCount();
84  uno::Reference< drawing::XShapes > xShapes = m_pContainer->getSection();
85  xContext = XMLShapeImportHelper::CreateGroupChildContext(GetImport(),nElement,xAttrList,xShapes);
86  m_bContainsShape = true;
87  if (m_pCellParent)
88  {
89  // #i94115 say to the parent Cell it contains shapes
91  }
92  }
93  break;
94  default:
95  SAL_WARN("reportdesign", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
96  break;
97  }
98 
99  return xContext;
100 }
101 
103 {
104  if ( !m_bContainsShape )
105  return;
106 
107  m_xReportComponent.set(m_pContainer->getSection()->getByIndex(m_nCurrentCount),uno::UNO_QUERY);
108  if ( !m_xReportComponent.is() )
109  return;
110 
111  if ( !m_aMasterFields.empty() )
112  m_xReportComponent->setMasterFields(Sequence< OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size()));
113  if ( !m_aDetailFields.empty() )
114  m_xReportComponent->setDetailFields(Sequence< OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size()));
115 
116  m_xReportComponent->setName(m_xFake->getName());
117  m_xReportComponent->setPrintRepeatedValues(m_xFake->getPrintRepeatedValues());
118  uno::Reference< report::XReportControlModel > xFakeModel(m_xFake,uno::UNO_QUERY);
119  uno::Reference< report::XReportControlModel > xComponentModel(m_xReportComponent,uno::UNO_QUERY);
120  if ( !(xComponentModel.is() && xFakeModel.is()) )
121  return;
122 
123  xComponentModel->setPrintWhenGroupChange(xFakeModel->getPrintWhenGroupChange());
124  const sal_Int32 nCount = xFakeModel->getCount();
125  try
126  {
127  for (sal_Int32 i = 0; i < nCount ; ++i)
128  {
129  uno::Reference< report::XFormatCondition > xCond(xFakeModel->getByIndex(i),uno::UNO_QUERY);
130  uno::Reference< report::XFormatCondition > xNewCond = xComponentModel->createFormatCondition();
131  ::comphelper::copyProperties(xCond, xNewCond);
132  xComponentModel->insertByIndex(xComponentModel->getCount(),uno::makeAny(xNewCond));
133  }
134  }
135  catch(uno::Exception&)
136  {
137  OSL_FAIL("Can not access format condition!");
138  }
139 }
140 
141 void OXMLSubDocument::addMasterDetailPair(const ::std::pair< OUString,OUString >& _aPair)
142 {
143  m_aMasterFields.push_back(_aPair.first);
144  m_aDetailFields.push_back(_aPair.second);
145 }
146 
147 } // namespace rptxml
148 
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
XML_BODY
virtual ~OXMLSubDocument() override
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
DRAW
int nCount
XML_FRAME
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
::std::vector< OUString > m_aDetailFields
void Increment(sal_Int32 nInc=1)
void setContainsShape(bool _bContainsShapes)
Definition: xmlCell.cxx:253
int i
XML_MASTER_DETAIL_FIELDS
ProgressBarHelper * GetProgressBarHelper()
virtual void addMasterDetailPair(const ::std::pair< OUString, OUString > &_aPair) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
css::uno::Reference< css::report::XReportComponent > m_xReportComponent
#define XML_ELEMENT(prefix, name)
const css::uno::Reference< css::report::XSection > & getSection() const
Definition: xmlTable.hxx:82
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:22
#define SAL_WARN(area, stream)
static SvXMLShapeContext * CreateGroupChildContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes, bool bTemporaryShape=false)
::std::vector< OUString > m_aMasterFields
OXMLSubDocument(const OXMLSubDocument &)=delete
css::uno::Reference< css::report::XReportComponent > m_xFake
REPORT
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override