LibreOffice Module lotuswordpro (master) 1
xftable.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56/*************************************************************************
57 * @file
58 * Table object.
59 ************************************************************************/
60#include <xfilter/xftable.hxx>
62#include <xfilter/xfrow.hxx>
63#include <xfilter/xfglobal.hxx>
64#include <cassert>
65
67{
69 m_bSubTable = false;
70 m_pOwnerCell = nullptr;
71}
72
74{
75 m_aRows.clear();
76 m_aColumns.clear();
77}
78
79void XFTable::SetColumnStyle(sal_Int32 col, const OUString& style)
80{
81 m_aColumns[col] = style;
82}
83
84bool XFTable::ContainsTable(const XFTable* pTable) const
85{
86 for (auto const& elem : m_aRows)
87 {
88 const XFRow *pRow = elem.second.get();
89
90 for (sal_Int32 i = 0; i < pRow->GetCellCount(); ++i)
91 {
92 const XFCell* pCell = pRow->GetCell(i + 1); //starts at 1, not 0
93 if (const XFTable* pSubTable = pCell->GetSubTable())
94 {
95 if (pSubTable == pTable)
96 return true;
97 if (pSubTable->ContainsTable(pTable))
98 return true;
99 }
100 if (pCell->HierarchyContains(pTable))
101 return true;
102 }
103 }
104
105 return false;
106}
107
109{
110 assert(rRow);
111
112 for (sal_Int32 i = 0; i < rRow->GetCellCount(); ++i)
113 {
114 XFCell* pFirstCell = rRow->GetCell(i + 1); //starts at 1, not 0
115 if (const XFTable* pSubTable = pFirstCell->GetSubTable())
116 {
117 if (pSubTable == this || pSubTable->ContainsTable(this))
118 throw std::runtime_error("table is a subtable of itself");
119 }
120 if (pFirstCell->HierarchyContains(this))
121 throw std::runtime_error("table is a subtable of itself");
122
123 }
124
125 int row = rRow->GetRow();
126
127 if( row<1 )
128 rRow->SetRow(m_aRows.size()+1);
129
130 row = rRow->GetRow();
131
132 rRow->SetOwnerTable(this);
133 m_aRows[row] = rRow;
134}
135
137{
138 if( !pRow)
139 return;
140 if (!m_aHeaderRows.is())
141 return;
142 m_aHeaderRows->Add(pRow);
143}
144
146{
147 if( m_bSubTable )
148 {
149 return m_pOwnerCell->GetCellName();
150 }
151 else
152 return m_strName;
153}
154
156{
157 sal_uInt16 rowMax = 0;
158 for (auto const& row : m_aRows)
159 {
160 if (row.first > rowMax)
161 rowMax = row.first;
162 }
163
164 return rowMax;
165}
166
167XFRow* XFTable::GetRow(sal_Int32 row)
168{
169 return m_aRows[row].get();
170}
171
173{
174 int colMax = -1;
175 for (auto const& column : m_aColumns)
176 {
177 if( column.first>colMax )
178 colMax = column.first;
179 }
180 return colMax;
181}
182
184{
185 return enumXFContentTable;
186}
187
189{
190 IXFAttrList *pAttrList = pStrm->GetAttrList();
191
192 pAttrList->Clear();
193 //sub table shouldn't use table name.
194 if( !m_bSubTable )
195 pAttrList->AddAttribute( "table:name", m_strName);
196
197 if( !GetStyleName().isEmpty() )
198 pAttrList->AddAttribute( "table:style-name", GetStyleName() );
199
200 if( m_bSubTable )
201 pStrm->StartElement( "table:sub-table" );
202 else
203 pStrm->StartElement( "table:table" );
204
205 //output columns:
206 {
207 int lastCol = 0;
208 for (auto const& column : m_aColumns)
209 {
210 sal_Int32 col = column.first;
211 OUString style = m_aColumns[col];
212
213 //default col repeated:
214 if( col >lastCol+1 )
215 {
216 if( col > lastCol + 2 )
217 {
218 if( !m_strDefColStyle.isEmpty() )
219 {
220 pAttrList->AddAttribute( "table:style-name", m_strDefColStyle );
221 }
222 pAttrList->AddAttribute( "table:number-columns-repeated", OUString::number(col-lastCol-1) );
223 }
224 pStrm->StartElement( "table:table-column" );
225 pStrm->EndElement( "table:table-column" );
226 }
227
228 if( !style.isEmpty() )
229 {
230 pAttrList->AddAttribute( "table:style-name", style );
231 }
232 pStrm->StartElement( "table:table-column" );
233 pStrm->EndElement( "table:table-column" );
234 lastCol = col;
235 }
236 }
237
238 if (m_aHeaderRows.is() && m_aHeaderRows->GetCount()>0)
239 {
240 pStrm->StartElement( "table:table-header-rows" );
241 m_aHeaderRows->ToXml(pStrm);
242 pStrm->EndElement( "table:table-header-rows" );
243 }
244 //output rows:
245 {
246 int lastRow = 0;
247
248 for (auto const& elem : m_aRows)
249 {
250 int row = elem.first;
251 XFRow *pRow = elem.second.get();
252
253 //null row repeated:
254 if( row>lastRow+1 )
255 {
256 XFRow *pNullRow = new XFRow();
258 if( row>lastRow+2)
259 pNullRow->SetRepeated(row-lastRow-1);
261 xCell->SetStyleName(m_strDefCellStyle);
262 pNullRow->AddCell(xCell);
263 pNullRow->ToXml(pStrm);
264 }
265 pRow->ToXml(pStrm);
266 lastRow = row;
267 }
268 }
269
270 if( m_bSubTable )
271 pStrm->EndElement( "table:sub-table" );
272 else
273 pStrm->EndElement( "table:table" );
274}
275/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
@descr Table cell object.
Definition: xfcell.hxx:76
const XFTable * GetSubTable() const
Definition: xfcell.hxx:145
OUString GetCellName()
@descr Return cell name.
Definition: xfcell.cxx:136
bool HierarchyContains(const XFContent *pContent) const
const OUString & GetStyleName() const
: return the style name.
Definition: xfcontent.hxx:95
virtual void SetStyleName(const OUString &style)
: All content except XFTextContent can have a style.
Definition: xfcontent.hxx:90
static OUString GenTableName()
@descr Generate a name for a table.
Definition: xfglobal.cxx:84
Definition: xfrow.hxx:69
void SetRepeated(sal_Int32 repeat)
Definition: xfrow.hxx:101
XFCell * GetCell(sal_Int32 col) const
Definition: xfrow.cxx:95
void AddCell(rtl::Reference< XFCell > const &rCell)
Definition: xfrow.cxx:79
sal_Int32 GetCellCount() const
Definition: xfrow.cxx:89
virtual void ToXml(IXFStream *pStrm) override
Definition: xfrow.cxx:104
bool m_bSubTable
Definition: xftable.hxx:110
OUString GetTableName()
Definition: xftable.cxx:145
enumXFContent GetContentType() override
: return the content type.
Definition: xftable.cxx:183
std::map< sal_Int32, OUString > m_aColumns
Definition: xftable.hxx:114
XFCell * m_pOwnerCell
Definition: xftable.hxx:111
OUString m_strDefRowStyle
Definition: xftable.hxx:116
OUString m_strDefColStyle
Definition: xftable.hxx:117
bool ContainsTable(const XFTable *pTable) const
Definition: xftable.cxx:84
sal_uInt16 GetRowCount()
Definition: xftable.cxx:155
void SetColumnStyle(sal_Int32 col, const OUString &style)
Definition: xftable.cxx:79
OUString m_strName
Definition: xftable.hxx:109
XFRow * GetRow(sal_Int32 row)
Definition: xftable.cxx:167
void AddRow(rtl::Reference< XFRow > const &rRow)
Definition: xftable.cxx:108
virtual void ToXml(IXFStream *pStrm) override
Definition: xftable.cxx:188
virtual ~XFTable() override
Definition: xftable.cxx:73
std::map< sal_uInt16, rtl::Reference< XFRow > > m_aRows
Definition: xftable.hxx:113
XFTable()
Definition: xftable.cxx:66
OUString m_strDefCellStyle
Definition: xftable.hxx:115
rtl::Reference< XFContentContainer > m_aHeaderRows
Definition: xftable.hxx:112
void AddHeaderRow(XFRow *pRow)
Definition: xftable.cxx:136
sal_Int32 GetColumnCount()
Definition: xftable.cxx:172
RttiCompleteObjectLocator col
int i
enumXFContent
Definition: xfdefs.hxx:64
@ enumXFContentTable
Definition: xfdefs.hxx:70