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>
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>
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
42namespace rptxml
43{
44 using namespace ::com::sun::star;
45 using namespace uno;
46 using namespace beans;
47 using namespace xml::sax;
48
49
50OXMLCell::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
83OXMLCell::~OXMLCell()
84{
85}
86
87css::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 {
100 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
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 {
112 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
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 {
124 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
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 {
135 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
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
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() )
164 m_pContainer->addCell(m_xComponent);
165
166 return xContext;
167}
168
169void OXMLCell::endFastElement(sal_Int32)
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();
192 m_pContainer->getSection()->add(m_xComponent);
193 m_pContainer->addCell(m_xComponent);
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
225 OXMLHelper::copyStyleElements(GetOwnImport().isOldFormat(),m_sStyleName,GetImport().GetAutoStyles(),m_xComponent);
226}
227
228ORptFilter& OXMLCell::GetOwnImport()
229{
230 return static_cast<ORptFilter&>(GetImport());
231}
232
233void OXMLCell::setComponent(const uno::Reference< report::XReportComponent >& _xComponent)
234{
235 m_pCell->m_xComponent = _xComponent;
236 m_xComponent = _xComponent;
237}
238
239void 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
253void 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: */
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
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)
OXMLCell(const OXMLCell &)=delete
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
DRAW
#define SAL_WARN(area, stream)
REPORT
int i
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString toString(OptionInfo const *info)
XML_FORMATTED_TEXT
XML_PAGE_COUNT
XML_FRAME
XML_PAGE_NUMBER
XML_P
XML_FIXED_CONTENT
XML_SUB_DOCUMENT
XML_IMAGE
XML_CUSTOM_SHAPE
sal_Int32 toInt32(std::u16string_view rStr)
constexpr OUStringLiteral PROPERTY_BORDERLEFT
Definition: strings.hxx:274
constexpr OUStringLiteral SERVICE_FIXEDLINE
Definition: strings.hxx:29
constexpr OUStringLiteral SERVICE_IMAGECONTROL
Definition: strings.hxx:24
constexpr OUStringLiteral SERVICE_FORMATTEDFIELD
Definition: strings.hxx:23
constexpr OUStringLiteral PROPERTY_BORDERRIGHT
Definition: strings.hxx:275
TEXT
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:22
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)