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