Line data Source code
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 "xftable.hxx"
61 : #include "xfrow.hxx"
62 : #include "xfcolstyle.hxx"
63 : #include "xfstylemanager.hxx"
64 : #include <cassert>
65 :
66 2 : XFTable::XFTable()
67 : {
68 2 : m_strName = XFGlobal::GenTableName();
69 2 : m_bSubTable = false;
70 2 : m_pOwnerCell = NULL;
71 2 : }
72 :
73 0 : XFTable::~XFTable()
74 : {
75 0 : std::map<sal_uInt16, XFRow*>::iterator it;
76 0 : for( it=m_aRows.begin(); it!=m_aRows.end(); ++it )
77 : {
78 0 : XFRow *pRow = (*it).second;
79 0 : delete pRow;
80 : }
81 0 : m_aRows.clear();
82 0 : m_aColumns.clear();
83 0 : }
84 :
85 8 : void XFTable::SetColumnStyle(sal_Int32 col, const OUString& style)
86 : {
87 8 : m_aColumns[col] = style;
88 8 : }
89 :
90 10 : void XFTable::AddRow(XFRow *pRow)
91 : {
92 : assert(pRow);
93 10 : if( !pRow )
94 10 : return;
95 :
96 10 : int row = pRow->GetRow();
97 :
98 10 : if( row<1 )
99 10 : pRow->SetRow(m_aRows.size()+1);
100 :
101 10 : row = pRow->GetRow();
102 10 : if( m_aRows.find(row) != m_aRows.end() )
103 0 : delete m_aRows[row];
104 :
105 10 : pRow->SetOwnerTable(this);
106 10 : m_aRows[row] = pRow;
107 : }
108 :
109 0 : void XFTable::AddHeaderRow(XFRow *pRow)
110 : {
111 0 : if( !pRow )
112 0 : return;
113 0 : m_aHeaderRows.Add(pRow);
114 : }
115 :
116 0 : OUString XFTable::GetTableName()
117 : {
118 0 : if( m_bSubTable )
119 : {
120 0 : return m_pOwnerCell->GetCellName();
121 : }
122 : else
123 0 : return m_strName;
124 : }
125 :
126 0 : sal_uInt16 XFTable::GetRowCount()
127 : {
128 0 : sal_uInt16 rowMax = 0;
129 0 : std::map<sal_uInt16, XFRow*>::iterator it;
130 0 : for( it=m_aRows.begin(); it!=m_aRows.end(); ++it )
131 : {
132 0 : if (it->first > rowMax)
133 0 : rowMax = it->first;
134 : }
135 :
136 0 : return rowMax;
137 : }
138 :
139 0 : XFRow* XFTable::GetRow(sal_Int32 row)
140 : {
141 0 : return m_aRows[row];
142 : }
143 :
144 0 : sal_Int32 XFTable::GetColumnCount()
145 : {
146 0 : int colMax = -1;
147 0 : std::map<sal_Int32,OUString>::iterator it;
148 0 : for( it=m_aColumns.begin(); it!=m_aColumns.end(); ++it )
149 : {
150 0 : if( it->first>colMax )
151 0 : colMax = it->first;
152 : }
153 0 : return colMax;
154 : }
155 :
156 0 : enumXFContent XFTable::GetContentType()
157 : {
158 0 : return enumXFContentTable;
159 : }
160 :
161 0 : void XFTable::ToXml(IXFStream *pStrm)
162 : {
163 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
164 :
165 0 : pAttrList->Clear();
166 : //sub table shouldn't use table name.
167 0 : if( !m_bSubTable )
168 0 : pAttrList->AddAttribute( "table:name", m_strName);
169 :
170 0 : if( !GetStyleName().isEmpty() )
171 0 : pAttrList->AddAttribute( "table:style-name", GetStyleName() );
172 :
173 0 : if( m_bSubTable )
174 0 : pStrm->StartElement( "table:sub-table" );
175 : else
176 0 : pStrm->StartElement( "table:table" );
177 :
178 : //output columns:
179 : {
180 0 : int lastCol = 0;
181 0 : std::map<sal_Int32,OUString>::iterator it;
182 0 : for( it=m_aColumns.begin(); it!=m_aColumns.end(); ++it )
183 : {
184 0 : sal_Int32 col = (*it).first;
185 0 : OUString style = m_aColumns[col];
186 :
187 : //default col repeated:
188 0 : if( col >lastCol+1 )
189 : {
190 0 : if( col > lastCol + 2 )
191 : {
192 0 : if( !m_strDefColStyle.isEmpty() )
193 : {
194 0 : pAttrList->AddAttribute( "table:style-name", m_strDefColStyle );
195 : }
196 0 : pAttrList->AddAttribute( "table:number-columns-repeated", OUString::number(col-lastCol-1) );
197 : }
198 0 : pStrm->StartElement( "table:table-column" );
199 0 : pStrm->EndElement( "table:table-column" );
200 : }
201 :
202 0 : if( !style.isEmpty() )
203 : {
204 0 : pAttrList->AddAttribute( "table:style-name", style );
205 : }
206 0 : pStrm->StartElement( "table:table-column" );
207 0 : pStrm->EndElement( "table:table-column" );
208 0 : lastCol = col;
209 0 : }
210 : }
211 :
212 0 : if( m_aHeaderRows.GetCount()>0 )
213 : {
214 0 : pStrm->StartElement( "table:table-header-rows" );
215 0 : m_aHeaderRows.ToXml(pStrm);
216 0 : pStrm->EndElement( "table:table-header-rows" );
217 : }
218 : //output rows:
219 : {
220 0 : int lastRow = 0;
221 :
222 0 : std::map<sal_uInt16, XFRow* >::iterator it = m_aRows.begin();
223 0 : for( ; it!=m_aRows.end(); ++it )
224 : {
225 0 : int row = (*it).first;
226 0 : XFRow *pRow = (*it).second;
227 :
228 : //null row repeated:
229 0 : if( row>lastRow+1 )
230 : {
231 0 : XFRow *pNullRow = new XFRow();
232 0 : pNullRow->SetStyleName(m_strDefRowStyle);
233 0 : if( row>lastRow+2)
234 0 : pNullRow->SetRepeated(row-lastRow-1);
235 0 : XFCell *pCell = new XFCell();
236 0 : pCell->SetStyleName(m_strDefCellStyle);
237 0 : pNullRow->AddCell(pCell);
238 0 : pNullRow->ToXml(pStrm);
239 : }
240 0 : pRow->ToXml(pStrm);
241 0 : lastRow = row;
242 : }
243 : }
244 :
245 0 : if( m_bSubTable )
246 0 : pStrm->EndElement( "table:sub-table" );
247 : else
248 0 : pStrm->EndElement( "table:table" );
249 0 : }
250 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|