LibreOffice Module reportdesign (master)  1
xmlCell.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 "xmlCell.hxx"
20 #include "xmlHelper.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnamespace.hxx>
24 #include <xmloff/prstylei.hxx>
25 #include <xmloff/xmlstyle.hxx>
27 #include "xmlEnums.hxx"
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/report/XShape.hpp>
30 #include <com/sun/star/report/XFixedLine.hpp>
31 #include <com/sun/star/table/BorderLine2.hpp>
32 #include <osl/diagnose.h>
33 #include <sal/log.hxx>
34 #include <tools/diagnose_ex.h>
35 #include <strings.hxx>
36 #include "xmlTable.hxx"
37 #include "xmlFormattedField.hxx"
38 #include "xmlImage.hxx"
39 #include "xmlFixedContent.hxx"
40 #include "xmlSubDocument.hxx"
41 
42 namespace rptxml
43 {
44  using namespace ::com::sun::star;
45  using namespace uno;
46  using namespace beans;
47  using namespace xml::sax;
48 
49 
50 OXMLCell::OXMLCell( ORptFilter& rImport
51  ,const Reference< XFastAttributeList > & _xAttrList
52  ,OXMLTable* _pContainer
53  ,OXMLCell* _pCell) :
54  SvXMLImportContext( rImport )
55  ,m_pContainer(_pContainer)
56  ,m_pCell(_pCell)
57  ,m_nCurrentCount(0)
58  ,m_bContainsShape(false)
59 {
60  if ( !m_pCell )
61  m_pCell = this;
62 
63  for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
64  {
65  switch( aIter.getToken() )
66  {
67  case XML_ELEMENT(TABLE, XML_STYLE_NAME):
68  m_sStyleName = aIter.toString();
69  break;
70  case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_SPANNED):
71  m_pContainer->setColumnSpanned(aIter.toInt32());
72  break;
73  case XML_ELEMENT(TABLE, XML_NUMBER_ROWS_SPANNED):
74  m_pContainer->setRowSpanned(aIter.toInt32());
75  break;
76  default:
77  XMLOFF_WARN_UNKNOWN("reportdesign", aIter);
78  break;
79  }
80  }
81 }
82 
84 {
85 }
86 
87 css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLCell::createFastChildContext(
88  sal_Int32 nElement,
89  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
90 {
91  css::uno::Reference< css::xml::sax::XFastContextHandler > xContext;
92  ORptFilter& rImport = GetOwnImport();
93  Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
94  static constexpr char16_t s_sStringConcat[] = u" & ";
95 
96  switch( nElement )
97  {
99  {
101  xContext = new OXMLFixedContent( rImport,*m_pCell,m_pContainer);
102  }
103  break;
105  m_sText += OUString::Concat(s_sStringConcat) + " PageNumber()";
106  break;
108  m_sText += OUString::Concat(s_sStringConcat) + " PageCount()";
109  break;
111  {
113  uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
114  Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
115 
116  OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
117  setComponent(xControl);
118  if ( xControl.is() )
119  xContext = new OXMLFormattedField( rImport,xAttrList,xControl,m_pContainer, false);
120  }
121  break;
123  {
125  Reference< XImageControl > xControl(xFactor->createInstance(SERVICE_IMAGECONTROL),uno::UNO_QUERY);
126 
127  OSL_ENSURE(xControl.is(),"Could not create ImageControl!");
128  setComponent(xControl);
129  if ( xControl.is() )
130  xContext = new OXMLImage( rImport,xAttrList,xControl,m_pContainer);
131  }
132  break;
134  {
136  if ( !m_bContainsShape )
137  m_nCurrentCount = m_pContainer->getSection()->getCount();
138  uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
139  Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
140  xContext = new OXMLSubDocument( rImport,xControl,m_pContainer, this /* give the current cell as parent*/ );
141  }
142  break;
143 
144  case XML_ELEMENT(TEXT, XML_P):
145  xContext = new OXMLCell( rImport,xAttrList ,m_pContainer,this);
146  break;
147 
149  case XML_ELEMENT(DRAW, XML_FRAME):
150  {
151  if ( !m_bContainsShape )
152  m_nCurrentCount = m_pContainer->getSection()->getCount();
153  uno::Reference< drawing::XShapes > xShapes = m_pContainer->getSection();
154  xContext = XMLShapeImportHelper::CreateGroupChildContext(rImport,nElement,xAttrList,xShapes);
155  m_bContainsShape = true;
156  }
157  break;
158 
159  default:
160  SAL_WARN("reportdesign", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
161  }
162 
163  if ( m_xComponent.is() )
165 
166  return xContext;
167 }
168 
170 {
171  if ( m_bContainsShape )
172  {
173  const sal_Int32 nCount = m_pContainer->getSection()->getCount();
174  for (sal_Int32 i = m_nCurrentCount; i < nCount; ++i)
175  {
176  uno::Reference<report::XShape> xShape(m_pContainer->getSection()->getByIndex(i),uno::UNO_QUERY);
177  if ( xShape.is() )
178  m_pContainer->addCell(xShape);
179  }
180  }
181  if ( m_pCell != this && !m_sText.isEmpty() )
182  {
183  ORptFilter& rImport = GetOwnImport();
184  Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
185  uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
186  Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
187  xControl->setDataField("rpt:" + m_sText);
188 
189  OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
190  setComponent(xControl);
191  m_xComponent = xControl.get();
194  }
195  // check if we have a FixedLine
196  else if ( !m_sStyleName.isEmpty() && !m_xComponent.is() && m_pCell == this )
197  {
198  ORptFilter& rImport = GetOwnImport();
199  Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
200  Reference<XFixedLine> xFixedLine(xFactor->createInstance(SERVICE_FIXEDLINE),uno::UNO_QUERY);
201  m_xComponent = xFixedLine.get();
202  m_pContainer->getSection()->add(m_xComponent);
203  m_pContainer->addCell(m_xComponent);
204  XMLPropStyleContext* pAutoStyle = const_cast<XMLPropStyleContext*>(dynamic_cast< const XMLPropStyleContext* >(GetImport().GetAutoStyles()->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sStyleName)));
205  if ( pAutoStyle )
206  {
207  uno::Reference<beans::XPropertySet> xBorderProp = OXMLHelper::createBorderPropertySet();
208  try
209  {
210  pAutoStyle->FillPropertySet(xBorderProp);
211  table::BorderLine2 aRight,aLeft;
212  xBorderProp->getPropertyValue(PROPERTY_BORDERRIGHT) >>= aRight;
213  xBorderProp->getPropertyValue(PROPERTY_BORDERLEFT) >>= aLeft;
214  const sal_Int16 rWidth = (aRight.LineWidth == 0) ? aRight.OuterLineWidth : aRight.LineWidth;
215  const sal_Int16 lWidth = (aLeft.LineWidth == 0) ? aLeft.OuterLineWidth : aLeft.LineWidth;
216  xFixedLine->setOrientation( (rWidth != 0 || lWidth != 0) ? 1 : 0);
217  }
218  catch(uno::Exception&)
219  {
220  TOOLS_WARN_EXCEPTION( "reportdesign", "OXMLCell::EndElement -> exception caught");
221  }
222  }
223  }
224  else
226 }
227 
229 {
230  return static_cast<ORptFilter&>(GetImport());
231 }
232 
233 void OXMLCell::setComponent(const uno::Reference< report::XReportComponent >& _xComponent)
234 {
235  m_pCell->m_xComponent = _xComponent;
236  m_xComponent = _xComponent;
237 }
238 
239 void OXMLCell::characters( const OUString& rChars )
240 {
241  if ( !rChars.isEmpty() )
242  {
243  static const char s_Quote[] = "\"";
244  if ( !m_sText.isEmpty() )
245  {
246  m_sText += " & ";
247  }
248 
249  m_sText += s_Quote + rChars + s_Quote;
250  }
251 }
252 
253 void OXMLCell::setContainsShape(bool _bContainsShape)
254 {
255  m_bContainsShape = _bContainsShape;
256 }
257 
258 
259 } // namespace rptxml
260 
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define PROPERTY_BORDERLEFT
Definition: strings.hxx:282
OXMLTable * m_pContainer
Definition: xmlCell.hxx:32
css::uno::Reference< css::report::XReportComponent > m_xComponent
Definition: xmlCell.hxx:31
#define SERVICE_IMAGECONTROL
Definition: strings.hxx:24
XML_PAGE_COUNT
SvXMLImport & GetImport()
sal_Int32 toInt32(OUString const &rStr)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
#define PROPERTY_BORDERRIGHT
Definition: strings.hxx:283
XML_IMAGE
void setComponent(const css::uno::Reference< css::report::XReportComponent > &_xComponent)
Definition: xmlCell.cxx:233
DRAW
int nCount
static void copyStyleElements(const bool _bOld, const OUString &_sStyleName, const SvXMLStylesContext *_pAutoStyles, const css::uno::Reference< css::beans::XPropertySet > &_xProp)
Definition: xmlHelper.cxx:248
#define XMLOFF_WARN_UNKNOWN(area, rIter)
static css::uno::Reference< css::beans::XPropertySet > createBorderPropertySet()
Definition: xmlHelper.cxx:317
XML_FRAME
OXMLCell(const OXMLCell &)=delete
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
XML_CUSTOM_SHAPE
#define SERVICE_FIXEDLINE
Definition: strings.hxx:29
void Increment(sal_Int32 nInc=1)
#define SERVICE_FORMATTEDFIELD
Definition: strings.hxx:23
void setContainsShape(bool _bContainsShapes)
Definition: xmlCell.cxx:253
#define TOOLS_WARN_EXCEPTION(area, stream)
int i
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
virtual void SAL_CALL characters(const OUString &rChars) override
Definition: xmlCell.cxx:239
sal_Int32 m_nCurrentCount
Definition: xmlCell.hxx:36
OUString m_sText
Definition: xmlCell.hxx:35
XML_FORMATTED_TEXT
float u
ProgressBarHelper * GetProgressBarHelper()
OXMLCell * m_pCell
Definition: xmlCell.hxx:33
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlCell.cxx:87
ORptFilter & GetOwnImport()
Definition: xmlCell.cxx:228
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlCell.cxx:169
OUString m_sStyleName
Definition: xmlCell.hxx:34
virtual ~OXMLCell() override
Definition: xmlCell.cxx:83
XML_PAGE_NUMBER
bool m_bContainsShape
Definition: xmlCell.hxx:37
XML_FIXED_CONTENT
XML_P
#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
const css::uno::Reference< css::frame::XModel > & GetModel() const
void addCell(const css::uno::Reference< css::report::XReportComponent > &_xElement)
Definition: xmlTable.cxx:256
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
#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)
XML_SUB_DOCUMENT
SvXMLStylesContext * GetAutoStyles()
TEXT
REPORT
OUString toString(OptionInfo const *info)