Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "xmlTable.hxx"
29 : : #include "xmlfilter.hxx"
30 : : #include <xmloff/xmltoken.hxx>
31 : : #include <xmloff/xmlnmspe.hxx>
32 : : #include <xmloff/nmspmap.hxx>
33 : : #include <xmloff/xmluconv.hxx>
34 : : #include "RptDef.hxx"
35 : : #include "xmlHelper.hxx"
36 : : #include "xmlEnums.hxx"
37 : : #include "xmlColumn.hxx"
38 : : #include <com/sun/star/report/ForceNewPage.hpp>
39 : : #include "xmlCondPrtExpr.hxx"
40 : : #include "xmlStyleImport.hxx"
41 : : #include "xmlstrings.hrc"
42 : : #include <connectivity/dbtools.hxx>
43 : : #include <tools/debug.hxx>
44 : : #include "xmlstrings.hrc"
45 : : #include <com/sun/star/report/XShape.hpp>
46 : : #include <com/sun/star/report/XFixedLine.hpp>
47 : :
48 : : #define MIN_WIDTH 80
49 : : #define MIN_HEIGHT 20
50 : :
51 : : namespace rptxml
52 : : {
53 : : using namespace ::xmloff;
54 : : using namespace ::com::sun::star;
55 : : using ::com::sun::star::uno::Reference;
56 : : using namespace ::com::sun::star::xml::sax;
57 : : using ::com::sun::star::xml::sax::XAttributeList;
58 : :
59 : 0 : sal_uInt16 lcl_getForceNewPageOption(const ::rtl::OUString& _sValue)
60 : : {
61 : 0 : sal_uInt16 nRet = report::ForceNewPage::NONE;
62 [ # # ]: 0 : const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetForceNewPageOptions();
63 [ # # ]: 0 : SvXMLUnitConverter::convertEnum( nRet,_sValue,aXML_EnumMap );
64 : 0 : return nRet;
65 : : }
66 : : DBG_NAME( rpt_OXMLTable )
67 : :
68 : 0 : OXMLTable::OXMLTable( ORptFilter& rImport
69 : : ,sal_uInt16 nPrfx
70 : : ,const ::rtl::OUString& _sLocalName
71 : : ,const Reference< XAttributeList > & _xAttrList
72 : : ,const uno::Reference< report::XSection >& _xSection
73 : : )
74 : : :SvXMLImportContext( rImport, nPrfx, _sLocalName )
75 : : ,m_xSection(_xSection)
76 : : ,m_nColSpan(1)
77 : : ,m_nRowSpan(0)
78 : : ,m_nRowIndex(0)
79 [ # # ][ # # ]: 0 : ,m_nColumnIndex(0)
[ # # ]
80 : : {
81 : : DBG_CTOR( rpt_OXMLTable,NULL);
82 : : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
83 : 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
84 [ # # ]: 0 : const SvXMLTokenMap& rTokenMap = rImport.GetSectionElemTokenMap();
85 : :
86 [ # # ][ # # ]: 0 : const sal_Int16 nLength = (m_xSection.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
[ # # ][ # # ]
87 [ # # ][ # # ]: 0 : static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
[ # # ][ # # ]
88 : : try
89 : : {
90 [ # # ]: 0 : for(sal_Int16 i = 0; i < nLength; ++i)
91 : : {
92 : 0 : rtl::OUString sLocalName;
93 [ # # ][ # # ]: 0 : const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
94 [ # # ]: 0 : const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
95 [ # # ][ # # ]: 0 : const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
96 : :
97 [ # # ][ # # : 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
# # # #
# ]
98 : : {
99 : : case XML_TOK_VISIBLE:
100 [ # # ][ # # ]: 0 : m_xSection->setVisible(sValue == s_sTRUE);
101 : 0 : break;
102 : : case XML_TOK_FORCE_NEW_PAGE:
103 [ # # ][ # # ]: 0 : m_xSection->setForceNewPage(lcl_getForceNewPageOption(sValue));
[ # # ]
104 : 0 : break;
105 : : case XML_TOK_FORCE_NEW_COLUMN:
106 [ # # ][ # # ]: 0 : m_xSection->setNewRowOrCol(lcl_getForceNewPageOption(sValue));
[ # # ]
107 : 0 : break;
108 : : case XML_TOK_KEEP_TOGETHER:
109 [ # # ][ # # ]: 0 : m_xSection->setKeepTogether(sValue == s_sTRUE);
110 : 0 : break;
111 : : case XML_TOK_SECTION_NAME:
112 [ # # ][ # # ]: 0 : m_xSection->setName(sValue);
113 : 0 : break;
114 : : case XML_TOK_SECT_STYLE_NAME:
115 : 0 : m_sStyleName = sValue;
116 : 0 : break;
117 : : default:
118 : 0 : break;
119 : : }
120 [ # # ]: 0 : }
121 : : }
122 [ # # ]: 0 : catch(Exception&)
123 : : {
124 : : OSL_FAIL("Exception catched while filling the section props");
125 : : }
126 : 0 : }
127 : : // -----------------------------------------------------------------------------
128 : 0 : OXMLTable::~OXMLTable()
129 : : {
130 : : DBG_DTOR( rpt_OXMLTable,NULL);
131 [ # # ]: 0 : }
132 : : // -----------------------------------------------------------------------------
133 : :
134 : 0 : SvXMLImportContext* OXMLTable::CreateChildContext(
135 : : sal_uInt16 _nPrefix,
136 : : const ::rtl::OUString& _rLocalName,
137 : : const Reference< XAttributeList > & xAttrList )
138 : : {
139 : 0 : SvXMLImportContext *pContext = 0;
140 : 0 : ORptFilter& rImport = GetOwnImport();
141 [ # # ]: 0 : const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
142 [ # # ]: 0 : Reference<XMultiServiceFactory> xFactor = rImport.getServiceFactory();
143 : :
144 [ # # ][ # # : 0 : switch( rTokenMap.Get( _nPrefix, _rLocalName ) )
# # # ]
145 : : {
146 : : case XML_TOK_TABLE_COLUMNS:
147 : : case XML_TOK_TABLE_ROWS:
148 [ # # ][ # # ]: 0 : pContext = new OXMLRowColumn( rImport, _nPrefix, _rLocalName,xAttrList ,this);
149 : 0 : break;
150 : : case XML_TOK_ROW:
151 [ # # ]: 0 : incrementRowIndex();
152 [ # # ][ # # ]: 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
153 [ # # ][ # # ]: 0 : pContext = new OXMLRowColumn( rImport, _nPrefix, _rLocalName,xAttrList,this);
154 : 0 : break;
155 : : case XML_TOK_COLUMN:
156 [ # # ][ # # ]: 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
157 [ # # ][ # # ]: 0 : pContext = new OXMLRowColumn( rImport, _nPrefix, _rLocalName,xAttrList,this);
158 : 0 : break;
159 : : case XML_TOK_CONDITIONAL_PRINT_EXPRESSION:
160 [ # # ][ # # ]: 0 : pContext = new OXMLCondPrtExpr( rImport, _nPrefix, _rLocalName,xAttrList,m_xSection.get());
[ # # ][ # # ]
[ # # ]
161 : 0 : break;
162 : : default:
163 : 0 : break;
164 : : }
165 : :
166 [ # # ]: 0 : if( !pContext )
167 [ # # ][ # # ]: 0 : pContext = new SvXMLImportContext( rImport, _nPrefix, _rLocalName );
168 : :
169 : 0 : return pContext;
170 : : }
171 : : // -----------------------------------------------------------------------------
172 : 0 : ORptFilter& OXMLTable::GetOwnImport()
173 : : {
174 : 0 : return static_cast<ORptFilter&>(GetImport());
175 : : }
176 : : // -----------------------------------------------------------------------------
177 : 0 : void OXMLTable::EndElement()
178 : : {
179 : : try
180 : : {
181 [ # # ]: 0 : if ( m_xSection.is() )
182 : : {
183 [ # # ]: 0 : if ( !m_sStyleName.isEmpty() )
184 : : {
185 [ # # ]: 0 : const SvXMLStylesContext* pAutoStyles = GetImport().GetAutoStyles();
186 [ # # ]: 0 : if ( pAutoStyles )
187 : : {
188 [ # # ][ # # ]: 0 : XMLPropStyleContext* pAutoStyle = PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_TABLE,m_sStyleName));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
189 [ # # ]: 0 : if ( pAutoStyle )
190 : : {
191 [ # # ][ # # ]: 0 : pAutoStyle->FillPropertySet(m_xSection.get());
[ # # ][ # # ]
192 : : }
193 : : }
194 : : }
195 : : // set height
196 : 0 : ::std::vector<sal_Int32>::iterator aIter = m_aHeight.begin();
197 : 0 : ::std::vector<sal_Int32>::iterator aEnd = m_aHeight.end();
198 : 0 : sal_Int32 nHeight = 0;
199 [ # # ][ # # ]: 0 : for (; aIter != aEnd; ++aIter)
[ # # ]
200 [ # # ]: 0 : nHeight += *aIter;
201 [ # # ][ # # ]: 0 : m_xSection->setHeight( nHeight );
202 : : // set positions, widths, and heights
203 [ # # ][ # # ]: 0 : sal_Int32 nLeftMargin = rptui::getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_LEFTMARGIN);
[ # # ][ # # ]
204 : 0 : sal_Int32 nPosY = 0;
205 : 0 : ::std::vector< ::std::vector<TCell> >::iterator aRowIter = m_aGrid.begin();
206 : 0 : ::std::vector< ::std::vector<TCell> >::iterator aRowEnd = m_aGrid.end();
207 [ # # ][ # # ]: 0 : for (sal_Int32 i = 0; aRowIter != aRowEnd; ++aRowIter,++i)
208 : : {
209 : 0 : sal_Int32 nPosX = nLeftMargin;
210 : 0 : ::std::vector<TCell>::iterator aColIter = (*aRowIter).begin();
211 : 0 : ::std::vector<TCell>::iterator aColEnd = (*aRowIter).end();
212 [ # # ][ # # ]: 0 : for (sal_Int32 j = 0; aColIter != aColEnd; ++aColIter,++j)
213 : : {
214 : 0 : TCell& rCell = *aColIter;
215 [ # # ]: 0 : if ( !rCell.xElements.empty())
216 : : {
217 : 0 : ::std::vector< uno::Reference< report::XReportComponent> >::iterator aCellIter = rCell.xElements.begin();
218 : 0 : const ::std::vector< uno::Reference< report::XReportComponent> >::iterator aCellEnd = rCell.xElements.end();
219 [ # # ][ # # ]: 0 : for (;aCellIter != aCellEnd ; ++aCellIter)
220 : : {
221 [ # # ]: 0 : uno::Reference<report::XShape> xShape(*aCellIter,uno::UNO_QUERY);
222 [ # # ]: 0 : if ( xShape.is() )
223 : : {
224 [ # # ][ # # ]: 0 : xShape->setPositionX(xShape->getPositionX() + nLeftMargin);
[ # # ][ # # ]
225 : : }
226 : : else
227 : : {
228 : 0 : sal_Int32 nWidth = rCell.nWidth;
229 : 0 : sal_Int32 nColSpan = rCell.nColSpan;
230 [ # # ]: 0 : if ( nColSpan > 1 )
231 : : {
232 [ # # ]: 0 : ::std::vector<TCell>::iterator aWidthIter = aColIter + 1;
233 [ # # ]: 0 : while ( nColSpan > 1 )
234 : : {
235 [ # # ]: 0 : nWidth += (aWidthIter++)->nWidth;
236 : 0 : --nColSpan;
237 : : }
238 : : }
239 : 0 : nHeight = rCell.nHeight;
240 : 0 : sal_Int32 nRowSpan = rCell.nRowSpan;
241 [ # # ]: 0 : if ( nRowSpan > 1 )
242 : : {
243 [ # # ]: 0 : ::std::vector< ::std::vector<TCell> >::iterator aHeightIter = aRowIter + 1;
244 [ # # ]: 0 : while( nRowSpan > 1)
245 : : {
246 : 0 : nHeight += (*aHeightIter)[j].nHeight;
247 : 0 : ++aHeightIter;
248 : 0 : --nRowSpan;
249 : : }
250 : : }
251 [ # # ]: 0 : Reference<XFixedLine> xFixedLine(*aCellIter,uno::UNO_QUERY);
252 [ # # ]: 0 : if ( xFixedLine.is() )
253 : : {
254 [ # # ][ # # ]: 0 : if ( xFixedLine->getOrientation() == 1 ) // vertical
[ # # ]
255 : : {
256 : : 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.");
257 [ # # ]: 0 : nWidth += m_aWidth[j+1];
258 [ # # ]: 0 : if ( nWidth < MIN_WIDTH )
259 : 0 : nWidth = MIN_WIDTH;
260 : : }
261 [ # # ]: 0 : else if ( nHeight < MIN_HEIGHT )
262 : 0 : nHeight = MIN_HEIGHT;
263 : : }
264 : : try
265 : : {
266 [ # # ][ # # ]: 0 : (*aCellIter)->setSize(awt::Size(nWidth,nHeight));
267 [ # # ][ # # ]: 0 : (*aCellIter)->setPosition(awt::Point(nPosX,nPosY));
268 : : }
269 [ # # # # ]: 0 : catch(beans::PropertyVetoException)
270 : : {
271 : : OSL_FAIL("Could not set the correct position or size!");
272 [ # # ]: 0 : }
273 : : }
274 [ # # ]: 0 : }
275 : : }
276 [ # # ]: 0 : nPosX += m_aWidth[j];
277 : : }
278 [ # # ]: 0 : nPosY += m_aHeight[i];
279 : : }
280 : : }
281 : : }
282 : 0 : catch(Exception&)
283 : : {
284 : : OSL_FAIL("OXMLTable::EndElement -> exception catched");
285 : : }
286 : 0 : }
287 : : // -----------------------------------------------------------------------------
288 : 0 : void OXMLTable::addCell(const Reference<XReportComponent>& _xElement)
289 : : {
290 [ # # ]: 0 : uno::Reference<report::XShape> xShape(_xElement,uno::UNO_QUERY);
291 : : 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(),
292 : : "OXMLTable::addCell: Invalid column and row index");
293 [ # # ][ # # ]: 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() )
[ # # ]
294 : : {
295 : 0 : TCell& rCell = m_aGrid[m_nRowIndex-1][m_nColumnIndex-1];
296 [ # # ]: 0 : if ( _xElement.is() )
297 [ # # ]: 0 : rCell.xElements.push_back( _xElement );
298 [ # # ]: 0 : if ( !xShape.is() )
299 : : {
300 [ # # ]: 0 : rCell.nWidth = m_aWidth[m_nColumnIndex-1];
301 [ # # ]: 0 : rCell.nHeight = m_aHeight[m_nRowIndex-1];
302 : 0 : rCell.nColSpan = m_nColSpan;
303 : 0 : rCell.nRowSpan = m_nRowSpan;
304 : : }
305 : : }
306 : :
307 [ # # ]: 0 : if ( !xShape.is() )
308 : 0 : m_nColSpan = m_nRowSpan = 1;
309 : 0 : }
310 : : // -----------------------------------------------------------------------------
311 : 0 : void OXMLTable::incrementRowIndex()
312 : : {
313 : 0 : ++m_nRowIndex;
314 : 0 : m_nColumnIndex = 0;
315 [ # # ]: 0 : m_aGrid.push_back(::std::vector<TCell>(m_aWidth.size()));
316 : 0 : }
317 : : //----------------------------------------------------------------------------
318 : : } // namespace rptxml
319 : : // -----------------------------------------------------------------------------
320 : :
321 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|