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 : #include "xmlCell.hxx"
20 : #include "xmlHelper.hxx"
21 : #include <xmloff/xmluconv.hxx>
22 : #include "xmlfilter.hxx"
23 : #include <xmloff/xmltoken.hxx>
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <xmloff/nmspmap.hxx>
26 : #include "xmlEnums.hxx"
27 : #include <tools/debug.hxx>
28 : #include "xmlStyleImport.hxx"
29 : #include <comphelper/namecontainer.hxx>
30 : #include <comphelper/genericpropertyset.hxx>
31 : #include <com/sun/star/beans/PropertyAttribute.hpp>
32 : #include <com/sun/star/report/XShape.hpp>
33 : #include <com/sun/star/report/XFixedLine.hpp>
34 : #include <com/sun/star/table/BorderLine2.hpp>
35 : #include "xmlstrings.hrc"
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 ::comphelper;
45 : using namespace ::com::sun::star;
46 : using namespace uno;
47 : using namespace beans;
48 : using namespace xml::sax;
49 :
50 :
51 0 : OXMLCell::OXMLCell( ORptFilter& rImport
52 : ,sal_uInt16 nPrfx
53 : ,const OUString& _sLocalName
54 : ,const Reference< XAttributeList > & _xAttrList
55 : ,OXMLTable* _pContainer
56 : ,OXMLCell* _pCell) :
57 : SvXMLImportContext( rImport, nPrfx, _sLocalName )
58 : ,m_pContainer(_pContainer)
59 : ,m_pCell(_pCell)
60 : ,m_nCurrentCount(0)
61 0 : ,m_bContainsShape(false)
62 : {
63 0 : if ( !m_pCell )
64 0 : m_pCell = this;
65 :
66 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
67 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
68 0 : const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
69 :
70 0 : const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
71 0 : for(sal_Int16 i = 0; i < nLength; ++i)
72 : {
73 0 : OUString sLocalName;
74 0 : const OUString sAttrName = _xAttrList->getNameByIndex( i );
75 0 : const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
76 0 : const OUString sValue = _xAttrList->getValueByIndex( i );
77 :
78 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
79 : {
80 : case XML_TOK_COLUMN_STYLE_NAME:
81 0 : m_sStyleName = sValue;
82 0 : break;
83 : case XML_TOK_NUMBER_COLUMNS_SPANNED:
84 0 : m_pContainer->setColumnSpanned(sValue.toInt32());
85 0 : break;
86 : case XML_TOK_NUMBER_ROWS_SPANNED:
87 0 : m_pContainer->setRowSpanned(sValue.toInt32());
88 0 : break;
89 : default:
90 0 : break;
91 : }
92 0 : }
93 0 : }
94 :
95 0 : OXMLCell::~OXMLCell()
96 : {
97 0 : }
98 :
99 0 : SvXMLImportContext* OXMLCell::CreateChildContext(
100 : sal_uInt16 _nPrefix,
101 : const OUString& _rLocalName,
102 : const Reference< XAttributeList > & xAttrList )
103 : {
104 0 : SvXMLImportContext *pContext = 0;
105 0 : ORptFilter& rImport = GetOwnImport();
106 0 : const SvXMLTokenMap& rTokenMap = rImport.GetCellElemTokenMap();
107 0 : Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
108 0 : static const OUString s_sStringConcat(" & ");
109 :
110 0 : const sal_uInt16 nToken = rTokenMap.Get( _nPrefix, _rLocalName );
111 0 : switch( nToken )
112 : {
113 : case XML_TOK_FIXED_CONTENT:
114 : {
115 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
116 0 : pContext = new OXMLFixedContent( rImport, _nPrefix, _rLocalName,*m_pCell,m_pContainer);
117 : }
118 0 : break;
119 : case XML_TOK_PAGE_NUMBER:
120 0 : m_sText += s_sStringConcat + " PageNumber()";
121 0 : break;
122 : case XML_TOK_PAGE_COUNT:
123 0 : m_sText += s_sStringConcat + " PageCount()";
124 0 : break;
125 : case XML_TOK_FORMATTED_TEXT:
126 : {
127 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
128 0 : uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
129 0 : Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
130 :
131 : OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
132 0 : setComponent(xControl.get());
133 0 : if ( xControl.is() )
134 0 : pContext = new OXMLFormattedField( rImport, _nPrefix, _rLocalName,xAttrList,xControl.get(),m_pContainer,XML_TOK_PAGE_COUNT == nToken);
135 : }
136 0 : break;
137 : case XML_TOK_IMAGE:
138 : {
139 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
140 0 : Reference< XImageControl > xControl(xFactor->createInstance(SERVICE_IMAGECONTROL),uno::UNO_QUERY);
141 :
142 : OSL_ENSURE(xControl.is(),"Could not create ImageControl!");
143 0 : setComponent(xControl.get());
144 0 : if ( xControl.is() )
145 0 : pContext = new OXMLImage( rImport, _nPrefix, _rLocalName,xAttrList,xControl.get(),m_pContainer);
146 : }
147 0 : break;
148 : case XML_TOK_SUB_DOCUMENT:
149 : {
150 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
151 0 : if ( !m_bContainsShape )
152 0 : m_nCurrentCount = m_pContainer->getSection()->getCount();
153 0 : uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
154 0 : Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
155 0 : pContext = new OXMLSubDocument( rImport, _nPrefix, _rLocalName,xControl.get(),m_pContainer, this /* give the current cell as parent*/ );
156 : }
157 0 : break;
158 :
159 : case XML_TOK_P:
160 0 : pContext = new OXMLCell( rImport, _nPrefix, _rLocalName,xAttrList ,m_pContainer,this);
161 0 : break;
162 : case XML_TOK_CUSTOM_SHAPE:
163 : case XML_TOK_FRAME:
164 : {
165 0 : if ( !m_bContainsShape )
166 0 : m_nCurrentCount = m_pContainer->getSection()->getCount();
167 0 : rtl::Reference< XMLShapeImportHelper > xShapeImportHelper = rImport.GetShapeImport();
168 0 : uno::Reference< drawing::XShapes > xShapes = m_pContainer->getSection().get();
169 0 : pContext = xShapeImportHelper->CreateGroupChildContext(rImport,_nPrefix,_rLocalName,xAttrList,xShapes);
170 0 : m_bContainsShape = true;
171 : }
172 0 : break;
173 : default:
174 0 : break;
175 : }
176 :
177 0 : if ( m_xComponent.is() )
178 0 : m_pContainer->addCell(m_xComponent);
179 :
180 0 : if( !pContext )
181 0 : pContext = new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
182 :
183 0 : return pContext;
184 : }
185 :
186 0 : void OXMLCell::EndElement()
187 : {
188 0 : if ( m_bContainsShape )
189 : {
190 0 : const sal_Int32 nCount = m_pContainer->getSection()->getCount();
191 0 : for (sal_Int32 i = m_nCurrentCount; i < nCount; ++i)
192 : {
193 0 : uno::Reference<report::XShape> xShape(m_pContainer->getSection()->getByIndex(i),uno::UNO_QUERY);
194 0 : if ( xShape.is() )
195 0 : m_pContainer->addCell(xShape.get());
196 0 : }
197 : }
198 0 : if ( m_pCell != this && !m_sText.isEmpty() )
199 : {
200 0 : ORptFilter& rImport = GetOwnImport();
201 0 : Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
202 0 : uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
203 0 : Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
204 0 : xControl->setDataField(OUString("rpt:") + m_sText);
205 :
206 : OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
207 0 : setComponent(xControl.get());
208 0 : m_xComponent = xControl.get();
209 0 : m_pContainer->getSection()->add(m_xComponent.get());
210 0 : m_pContainer->addCell(m_xComponent);
211 : }
212 : // check if we have a FixedLine
213 0 : else if ( !m_sStyleName.isEmpty() && !m_xComponent.is() && m_pCell == this )
214 : {
215 0 : ORptFilter& rImport = GetOwnImport();
216 0 : Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
217 0 : Reference<XFixedLine> xFixedLine(xFactor->createInstance(SERVICE_FIXEDLINE),uno::UNO_QUERY);
218 0 : m_xComponent = xFixedLine.get();
219 0 : m_pContainer->getSection()->add(m_xComponent.get());
220 0 : m_pContainer->addCell(m_xComponent);
221 0 : XMLPropStyleContext* pAutoStyle = const_cast<XMLPropStyleContext*>(PTR_CAST(XMLPropStyleContext,GetImport().GetAutoStyles()->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sStyleName)));
222 0 : if ( pAutoStyle )
223 : {
224 0 : uno::Reference<beans::XPropertySet> xBorderProp = OXMLHelper::createBorderPropertySet();
225 : try
226 : {
227 0 : pAutoStyle->FillPropertySet(xBorderProp);
228 0 : table::BorderLine2 aRight,aLeft;
229 0 : xBorderProp->getPropertyValue(PROPERTY_BORDERRIGHT) >>= aRight;
230 0 : xBorderProp->getPropertyValue(PROPERTY_BORDERLEFT) >>= aLeft;
231 0 : const sal_Int16 rWidth = (aRight.LineWidth == 0) ? aRight.OuterLineWidth : aRight.LineWidth;
232 0 : const sal_Int16 lWidth = (aLeft.LineWidth == 0) ? aLeft.OuterLineWidth : aLeft.LineWidth;
233 0 : xFixedLine->setOrientation( (rWidth != 0 || lWidth != 0) ? 1 : 0);
234 : }
235 0 : catch(uno::Exception&)
236 : {
237 : OSL_FAIL("OXMLCell::EndElement -> exception catched");
238 0 : }
239 0 : }
240 : }
241 : else
242 0 : OXMLHelper::copyStyleElements(GetOwnImport().isOldFormat(),m_sStyleName,GetImport().GetAutoStyles(),m_xComponent.get());
243 0 : }
244 :
245 0 : ORptFilter& OXMLCell::GetOwnImport()
246 : {
247 0 : return static_cast<ORptFilter&>(GetImport());
248 : }
249 :
250 0 : void OXMLCell::setComponent(const uno::Reference< report::XReportComponent >& _xComponent)
251 : {
252 0 : m_pCell->m_xComponent = _xComponent;
253 0 : m_xComponent = _xComponent;
254 0 : }
255 :
256 0 : void OXMLCell::Characters( const OUString& rChars )
257 : {
258 0 : if ( !rChars.isEmpty() )
259 : {
260 0 : static const OUString s_Quote("\"");
261 0 : if ( !m_sText.isEmpty() )
262 : {
263 0 : static const OUString s_sStringConcat(" & ");
264 0 : m_sText += s_sStringConcat;
265 : }
266 :
267 0 : m_sText += s_Quote + rChars + s_Quote;
268 : }
269 0 : }
270 :
271 0 : void OXMLCell::setContainsShape(bool _bContainsShape)
272 : {
273 0 : m_bContainsShape = _bContainsShape;
274 0 : }
275 :
276 :
277 : } // namespace rptxml
278 :
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|