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