merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / inc / resourcemodel / TableData.hxx
bloba43f2530ffafa50f0000b82dbdfd5955a651e81f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableData.hxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_TABLE_DATA
32 #define INCLUDED_TABLE_DATA
34 #ifndef INCLUDED_WW8_RESOURCE_MODEL_HXX
35 #include <resourcemodel/WW8ResourceModel.hxx>
36 #endif
38 #include <vector>
39 #include <boost/shared_ptr.hpp>
41 namespace writerfilter
44 template <typename T, typename PropertiesPointer>
45 /**
46 Class containing the data to describe a table cell.
48 class WRITERFILTER_DLLPUBLIC CellData
50 /**
51 Handle to start of cell.
53 T mStart;
55 /**
56 Handle to end of cell.
58 T mEnd;
60 /**
61 Pointer to properties of cell.
63 PropertiesPointer mpProps;
65 bool mbOpen;
67 public:
68 typedef boost::shared_ptr<CellData> Pointer_t;
70 CellData(T start, PropertiesPointer pProps)
71 : mStart(start), mEnd(start), mpProps(pProps), mbOpen(true)
75 virtual ~CellData() {}
77 /**
78 Set the start handle of the cell.
80 @param start the start handle of the cell
82 void setStart(T start) { mStart = start; }
84 /**
85 Set the end handle of a cell.
87 @param end the end handle of the cell
89 void setEnd(T end) { mEnd = end; mbOpen = false; }
91 /**
92 Set the properties of the cell.
94 @param pProps the properties of the cell
96 void setProperties(PropertiesPointer pProps) { mpProps = pProps; }
98 /**
99 Adds properties to the cell.
101 @param pProps the properties to add
103 void insertProperties(PropertiesPointer pProps)
105 if( mpProps.get() )
106 mpProps->insert(pProps);
107 else
108 mpProps = pProps;
112 Return start handle of the cell.
114 const T & getStart() { return mStart; }
117 Return end handle of the cell.
119 const T & getEnd() { return mEnd; }
122 Return properties of the cell.
124 PropertiesPointer getProperties() { return mpProps; }
126 bool isOpen() const { return mbOpen; }
129 template <typename T, typename PropertiesPointer>
131 Class to handle data of a table row.
133 class WRITERFILTER_DLLPUBLIC RowData
135 typedef typename CellData<T, PropertiesPointer>::Pointer_t
136 CellDataPointer_t;
137 typedef ::std::vector<CellDataPointer_t> Cells;
140 the cell data of the row
142 Cells mCells;
145 the properties of the row
147 mutable PropertiesPointer mpProperties;
149 public:
150 typedef boost::shared_ptr<RowData <T, PropertiesPointer> > Pointer_t;
152 RowData() {}
154 RowData(const RowData<T, PropertiesPointer> & rRowData)
155 : mCells(rRowData.mCells), mpProperties(rRowData.mpProperties)
159 virtual ~RowData() {}
162 Add a cell to the row.
164 @param start the start handle of the cell
165 @param end the end handle of the cell
166 @param pProps the properties of the cell
168 void addCell(const T & start, PropertiesPointer pProps)
170 CellDataPointer_t pCellData
171 (new CellData<T, PropertiesPointer>(start, pProps));
172 mCells.push_back(pCellData);
175 void endCell(const T & end)
177 if (mCells.size() > 0)
178 mCells.back()->setEnd(end);
181 bool isCellOpen() const
183 return mCells.size() > 0 && mCells.back()->isOpen();
187 Add properties to the row.
189 @param pProperties the properties to set
191 void insertProperties(PropertiesPointer pProperties)
193 if( pProperties.get() )
195 if( !mpProperties.get() )
196 mpProperties = pProperties;
197 else
198 mpProperties->insert( pProperties );
203 Add properties to a cell of the row.
205 @param i index of the cell
206 @param pProps the properties to add
208 void insertCellProperties(unsigned int i, PropertiesPointer pProps)
210 mCells[i]->insertProperties(pProps);
214 Return number of cells in the row.
216 unsigned int getCellCount()
218 return mCells.size();
222 Return start handle of a cell in the row.
224 @param i index of the cell
226 const T & getCellStart(unsigned int i) const
228 return mCells[i]->getStart();
232 Return end handle of a cell in the row.
234 @param i index of the cell
236 const T & getCellEnd(unsigned int i) const
238 return mCells[i]->getEnd();
242 Return the properties of a cell in the row.
244 @param i index of the cell
246 PropertiesPointer getCellProperties(unsigned int i) const
248 return mCells[i]->getProperties();
252 Return properties of the row.
254 PropertiesPointer getProperties()
256 return mpProperties;
260 Clear the row data.
262 void clear()
264 mCells.clear();
265 mpProperties.reset();
269 template <typename T, typename PropertiesPointer>
271 Class that holds the data of a table.
273 class WRITERFILTER_DLLPUBLIC TableData
275 typedef typename RowData<T, PropertiesPointer>::Pointer_t RowPointer_t;
276 typedef ::std::vector<RowPointer_t> Rows;
279 the table properties
281 PropertiesPointer mpTableProps;
284 the data of the rows of the table
286 Rows mRows;
289 pointer to the data of the current row (while building up the table data).
291 RowPointer_t mpRow;
294 depth of the current table in a hierarchy of tables
296 unsigned int mnDepth;
299 initialize mpRow
301 void newRow() { mpRow = RowPointer_t(new RowData<T, PropertiesPointer>()); }
303 public:
304 typedef boost::shared_ptr<TableData <T, PropertiesPointer> > Pointer_t;
306 TableData(unsigned int nDepth) : mnDepth(nDepth) { newRow(); }
307 ~TableData() {}
310 End the current row.
312 Sets properties of the current row and pushes the row to the
313 back of the rows currently contained in the table.
315 @param pProperties properties of the row to be ended
317 void endRow(PropertiesPointer pProperties)
319 mpRow->insertProperties(pProperties);
320 mRows.push_back(mpRow);
321 newRow();
325 Add a cell to the current row.
327 @param start start handle of the cell
328 @param end end handle of the cell
329 @param pProps properties of the cell
331 void addCell(const T & start, PropertiesPointer pProps)
333 mpRow->addCell(start, pProps);
336 void endCell(const T & end)
338 mpRow->endCell(end);
341 bool isCellOpen() const
343 return mpRow->isCellOpen();
347 Add properties to a cell of the current row.
349 @param i index of the cell
350 @param pProps properties to add
352 void insertCellProperties(unsigned int i, PropertiesPointer pProps)
354 mpRow->insertCellProperties(i, pProps);
357 void insertTableProperties( PropertiesPointer pProps )
359 if ( mpTableProps.get( ) )
360 mpTableProps->insert( pProps );
361 else
362 mpTableProps = pProps;
366 Return the table properties.
368 PropertiesPointer getTableProperties( )
370 return mpTableProps;
374 Return number of rows in the table.
376 unsigned int getRowCount()
378 return mRows.size();
382 Return depth of table in surrounding table hierarchy.
384 unsigned int getDepth()
386 return mnDepth;
390 Return row data of a certain row.
392 @param i index of the row
394 const RowPointer_t getRow(unsigned int i) const
396 return mRows[i];
402 #endif // INCLUDED_TABLE_DATA