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 "xmlTable.hxx"
20 : #include "xmlfilter.hxx"
21 : #include <xmloff/xmltoken.hxx>
22 : #include <xmloff/xmlnmspe.hxx>
23 : #include <xmloff/nmspmap.hxx>
24 : #include <xmloff/xmluconv.hxx>
25 : #include "RptDef.hxx"
26 : #include "xmlHelper.hxx"
27 : #include "xmlEnums.hxx"
28 : #include "xmlColumn.hxx"
29 : #include <com/sun/star/report/ForceNewPage.hpp>
30 : #include "xmlCondPrtExpr.hxx"
31 : #include "xmlStyleImport.hxx"
32 : #include "xmlstrings.hrc"
33 : #include <connectivity/dbtools.hxx>
34 : #include <tools/debug.hxx>
35 : #include <com/sun/star/report/XShape.hpp>
36 : #include <com/sun/star/report/XFixedLine.hpp>
37 :
38 : #define MIN_WIDTH 80
39 : #define MIN_HEIGHT 20
40 :
41 : namespace rptxml
42 : {
43 : using namespace ::xmloff;
44 : using namespace ::com::sun::star;
45 : using ::com::sun::star::uno::Reference;
46 : using namespace ::com::sun::star::xml::sax;
47 : using ::com::sun::star::xml::sax::XAttributeList;
48 :
49 0 : sal_uInt16 lcl_getForceNewPageOption(const OUString& _sValue)
50 : {
51 0 : sal_uInt16 nRet = report::ForceNewPage::NONE;
52 0 : const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetForceNewPageOptions();
53 0 : SvXMLUnitConverter::convertEnum( nRet,_sValue,aXML_EnumMap );
54 0 : return nRet;
55 : }
56 : DBG_NAME( rpt_OXMLTable )
57 :
58 0 : OXMLTable::OXMLTable( ORptFilter& rImport
59 : ,sal_uInt16 nPrfx
60 : ,const OUString& _sLocalName
61 : ,const Reference< XAttributeList > & _xAttrList
62 : ,const uno::Reference< report::XSection >& _xSection
63 : )
64 : :SvXMLImportContext( rImport, nPrfx, _sLocalName )
65 : ,m_xSection(_xSection)
66 : ,m_nColSpan(1)
67 : ,m_nRowSpan(0)
68 : ,m_nRowIndex(0)
69 0 : ,m_nColumnIndex(0)
70 : {
71 : DBG_CTOR( rpt_OXMLTable,NULL);
72 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
73 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
74 0 : const SvXMLTokenMap& rTokenMap = rImport.GetSectionElemTokenMap();
75 :
76 0 : const sal_Int16 nLength = (m_xSection.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
77 0 : static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
78 : try
79 : {
80 0 : for(sal_Int16 i = 0; i < nLength; ++i)
81 : {
82 0 : OUString sLocalName;
83 0 : const OUString sAttrName = _xAttrList->getNameByIndex( i );
84 0 : const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
85 0 : const OUString sValue = _xAttrList->getValueByIndex( i );
86 :
87 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
88 : {
89 : case XML_TOK_VISIBLE:
90 0 : m_xSection->setVisible(sValue == s_sTRUE);
91 0 : break;
92 : case XML_TOK_FORCE_NEW_PAGE:
93 0 : m_xSection->setForceNewPage(lcl_getForceNewPageOption(sValue));
94 0 : break;
95 : case XML_TOK_FORCE_NEW_COLUMN:
96 0 : m_xSection->setNewRowOrCol(lcl_getForceNewPageOption(sValue));
97 0 : break;
98 : case XML_TOK_KEEP_TOGETHER:
99 0 : m_xSection->setKeepTogether(sValue == s_sTRUE);
100 0 : break;
101 : case XML_TOK_SECTION_NAME:
102 0 : m_xSection->setName(sValue);
103 0 : break;
104 : case XML_TOK_SECT_STYLE_NAME:
105 0 : m_sStyleName = sValue;
106 0 : break;
107 : default:
108 0 : break;
109 : }
110 0 : }
111 : }
112 0 : catch(Exception&)
113 : {
114 : OSL_FAIL("Exception catched while filling the section props");
115 : }
116 0 : }
117 : // -----------------------------------------------------------------------------
118 0 : OXMLTable::~OXMLTable()
119 : {
120 : DBG_DTOR( rpt_OXMLTable,NULL);
121 0 : }
122 : // -----------------------------------------------------------------------------
123 :
124 0 : SvXMLImportContext* OXMLTable::CreateChildContext(
125 : sal_uInt16 _nPrefix,
126 : const OUString& _rLocalName,
127 : const Reference< XAttributeList > & xAttrList )
128 : {
129 0 : SvXMLImportContext *pContext = 0;
130 0 : ORptFilter& rImport = GetOwnImport();
131 0 : const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
132 :
133 0 : switch( rTokenMap.Get( _nPrefix, _rLocalName ) )
134 : {
135 : case XML_TOK_TABLE_COLUMNS:
136 : case XML_TOK_TABLE_ROWS:
137 0 : pContext = new OXMLRowColumn( rImport, _nPrefix, _rLocalName,xAttrList ,this);
138 0 : break;
139 : case XML_TOK_ROW:
140 0 : incrementRowIndex();
141 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
142 0 : pContext = new OXMLRowColumn( rImport, _nPrefix, _rLocalName,xAttrList,this);
143 0 : break;
144 : case XML_TOK_COLUMN:
145 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
146 0 : pContext = new OXMLRowColumn( rImport, _nPrefix, _rLocalName,xAttrList,this);
147 0 : break;
148 : case XML_TOK_CONDITIONAL_PRINT_EXPRESSION:
149 0 : pContext = new OXMLCondPrtExpr( rImport, _nPrefix, _rLocalName,xAttrList,m_xSection.get());
150 0 : break;
151 : default:
152 0 : break;
153 : }
154 :
155 0 : if( !pContext )
156 0 : pContext = new SvXMLImportContext( rImport, _nPrefix, _rLocalName );
157 :
158 0 : return pContext;
159 : }
160 : // -----------------------------------------------------------------------------
161 0 : ORptFilter& OXMLTable::GetOwnImport()
162 : {
163 0 : return static_cast<ORptFilter&>(GetImport());
164 : }
165 : // -----------------------------------------------------------------------------
166 0 : void OXMLTable::EndElement()
167 : {
168 : try
169 : {
170 0 : if ( m_xSection.is() )
171 : {
172 0 : if ( !m_sStyleName.isEmpty() )
173 : {
174 0 : const SvXMLStylesContext* pAutoStyles = GetImport().GetAutoStyles();
175 0 : if ( pAutoStyles )
176 : {
177 0 : XMLPropStyleContext* pAutoStyle = PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_TABLE,m_sStyleName));
178 0 : if ( pAutoStyle )
179 : {
180 0 : pAutoStyle->FillPropertySet(m_xSection.get());
181 : }
182 : }
183 : }
184 : // set height
185 0 : ::std::vector<sal_Int32>::iterator aIter = m_aHeight.begin();
186 0 : ::std::vector<sal_Int32>::iterator aEnd = m_aHeight.end();
187 0 : sal_Int32 nHeight = 0;
188 0 : for (; aIter != aEnd; ++aIter)
189 0 : nHeight += *aIter;
190 0 : m_xSection->setHeight( nHeight );
191 : // set positions, widths, and heights
192 0 : sal_Int32 nLeftMargin = rptui::getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_LEFTMARGIN);
193 0 : sal_Int32 nPosY = 0;
194 0 : ::std::vector< ::std::vector<TCell> >::iterator aRowIter = m_aGrid.begin();
195 0 : ::std::vector< ::std::vector<TCell> >::iterator aRowEnd = m_aGrid.end();
196 0 : for (sal_Int32 i = 0; aRowIter != aRowEnd; ++aRowIter,++i)
197 : {
198 0 : sal_Int32 nPosX = nLeftMargin;
199 0 : ::std::vector<TCell>::iterator aColIter = (*aRowIter).begin();
200 0 : ::std::vector<TCell>::iterator aColEnd = (*aRowIter).end();
201 0 : for (sal_Int32 j = 0; aColIter != aColEnd; ++aColIter,++j)
202 : {
203 0 : TCell& rCell = *aColIter;
204 0 : if ( !rCell.xElements.empty())
205 : {
206 0 : ::std::vector< uno::Reference< report::XReportComponent> >::iterator aCellIter = rCell.xElements.begin();
207 0 : const ::std::vector< uno::Reference< report::XReportComponent> >::iterator aCellEnd = rCell.xElements.end();
208 0 : for (;aCellIter != aCellEnd ; ++aCellIter)
209 : {
210 0 : uno::Reference<report::XShape> xShape(*aCellIter,uno::UNO_QUERY);
211 0 : if ( xShape.is() )
212 : {
213 0 : xShape->setPositionX(xShape->getPositionX() + nLeftMargin);
214 : }
215 : else
216 : {
217 0 : sal_Int32 nWidth = rCell.nWidth;
218 0 : sal_Int32 nColSpan = rCell.nColSpan;
219 0 : if ( nColSpan > 1 )
220 : {
221 0 : ::std::vector<TCell>::iterator aWidthIter = aColIter + 1;
222 0 : while ( nColSpan > 1 )
223 : {
224 0 : nWidth += (aWidthIter++)->nWidth;
225 0 : --nColSpan;
226 : }
227 : }
228 0 : nHeight = rCell.nHeight;
229 0 : sal_Int32 nRowSpan = rCell.nRowSpan;
230 0 : if ( nRowSpan > 1 )
231 : {
232 0 : ::std::vector< ::std::vector<TCell> >::iterator aHeightIter = aRowIter + 1;
233 0 : while( nRowSpan > 1)
234 : {
235 0 : nHeight += (*aHeightIter)[j].nHeight;
236 0 : ++aHeightIter;
237 0 : --nRowSpan;
238 : }
239 : }
240 0 : Reference<XFixedLine> xFixedLine(*aCellIter,uno::UNO_QUERY);
241 0 : if ( xFixedLine.is() )
242 : {
243 0 : if ( xFixedLine->getOrientation() == 1 ) // vertical
244 : {
245 : OSL_ENSURE(static_cast<sal_uInt32>(j+1) < m_aWidth.size(),"Illegal pos of col iter. There should be an empty cell for the next line part.");
246 0 : nWidth += m_aWidth[j+1];
247 0 : if ( nWidth < MIN_WIDTH )
248 0 : nWidth = MIN_WIDTH;
249 : }
250 0 : else if ( nHeight < MIN_HEIGHT )
251 0 : nHeight = MIN_HEIGHT;
252 : }
253 : try
254 : {
255 0 : (*aCellIter)->setSize(awt::Size(nWidth,nHeight));
256 0 : (*aCellIter)->setPosition(awt::Point(nPosX,nPosY));
257 : }
258 0 : catch(beans::PropertyVetoException)
259 : {
260 : OSL_FAIL("Could not set the correct position or size!");
261 0 : }
262 : }
263 0 : }
264 : }
265 0 : nPosX += m_aWidth[j];
266 : }
267 0 : nPosY += m_aHeight[i];
268 : }
269 : }
270 : }
271 0 : catch(Exception&)
272 : {
273 : OSL_FAIL("OXMLTable::EndElement -> exception catched");
274 : }
275 0 : }
276 : // -----------------------------------------------------------------------------
277 0 : void OXMLTable::addCell(const Reference<XReportComponent>& _xElement)
278 : {
279 0 : uno::Reference<report::XShape> xShape(_xElement,uno::UNO_QUERY);
280 : OSL_ENSURE(static_cast<sal_uInt32>(m_nRowIndex-1 ) < m_aGrid.size() && static_cast<sal_uInt32>( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size(),
281 : "OXMLTable::addCell: Invalid column and row index");
282 0 : if ( static_cast<sal_uInt32>(m_nRowIndex-1 ) < m_aGrid.size() && static_cast<sal_uInt32>( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size() )
283 : {
284 0 : TCell& rCell = m_aGrid[m_nRowIndex-1][m_nColumnIndex-1];
285 0 : if ( _xElement.is() )
286 0 : rCell.xElements.push_back( _xElement );
287 0 : if ( !xShape.is() )
288 : {
289 0 : rCell.nWidth = m_aWidth[m_nColumnIndex-1];
290 0 : rCell.nHeight = m_aHeight[m_nRowIndex-1];
291 0 : rCell.nColSpan = m_nColSpan;
292 0 : rCell.nRowSpan = m_nRowSpan;
293 : }
294 : }
295 :
296 0 : if ( !xShape.is() )
297 0 : m_nColSpan = m_nRowSpan = 1;
298 0 : }
299 : // -----------------------------------------------------------------------------
300 0 : void OXMLTable::incrementRowIndex()
301 : {
302 0 : ++m_nRowIndex;
303 0 : m_nColumnIndex = 0;
304 0 : m_aGrid.push_back(::std::vector<TCell>(m_aWidth.size()));
305 0 : }
306 : //----------------------------------------------------------------------------
307 0 : } // namespace rptxml
308 : // -----------------------------------------------------------------------------
309 :
310 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|