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