Debian Codegraph @

src/lib/MWAWTable.hxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 /*
35 * Structure to store and construct a table from an unstructured list
36 * of cell
37 *
38 */
39
40 #ifndef MWAW_TABLE
41 # define MWAW_TABLE
42
43 #include <iostream>
44 #include <vector>
45
46 #include "libmwaw_internal.hxx"
47
48 #include "MWAWCell.hxx"
49
50 /** a class used to recreate the table structure using cell informations, .... */
51 class MWAWTable
52 {
53 public:
54 //! an enum used to indicate what the list of entries which are filled
55 enum DataSet {
56 CellPositionBit=1, BoxBit=2, SizeBit=4, TableDimBit=8, TablePosToCellBit=0x10
57 };
58 /** an enum do define the table alignment.
59
60 \note Paragraph means using the default alignment, left page alignment and use left margin */
61 enum Alignment {
62 Paragraph, Left, Center, Right
63 };
64 //! the constructor
65 explicit MWAWTable(uint32_t givenData=BoxBit)
66 : m_givenData(givenData)
67 , m_setData(givenData)
68 , m_mergeBorders(true)
69 , m_cellsList()
70 , m_numRows(0)
71 , m_numCols(0)
72 , m_rowsSize()
73 , m_colsSize()
74 , m_alignment(Paragraph)
75 , m_leftMargin(0)
76 , m_rightMargin(0)
77 , m_posToCellId()
78 , m_hasExtraLines(false)
79 {
80 }
81
82 //! the destructor
83 virtual ~MWAWTable();
84
85 //! add a new cells
86 void add(std::shared_ptr<MWAWCell> cell)
87 {
88 if (!cell) {
89 MWAW_DEBUG_MSG(("MWAWTable::add: must be called with a cell\n"));
90 return;
91 }
92 m_cellsList.push_back(cell);
93 }
94 //! returns true if we need to merge borders
95 bool mergeBorders() const
96 {
97 return m_mergeBorders;
98 }
99 //! sets the merge borders' value
100 bool setMergeBorders(bool val)
101 {
102 return m_mergeBorders=val;
103 }
104 /** defines the current alignment
105 \note: leftMargin,rightMargin are given in Points */
106 void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
107 {
108 m_alignment = align;
109 m_leftMargin = leftMargin;
110 m_rightMargin = rightMargin;
111 }
112 //! returns the number of cell
113 int numCells() const
114 {
115 return int(m_cellsList.size());
116 }
117 /** returns the row size if defined (in point) */
118 std::vector<float> const &getRowsSize() const
119 {
120 return m_rowsSize;
121 }
122 /** define the row size (in point) */
123 void setRowsSize(std::vector<float> const &rSize)
124 {
125 m_rowsSize=rSize;
126 }
127 /** returns the columns size if defined (in point) */
128 std::vector<float> const &getColsSize() const
129 {
130 return m_colsSize;
131 }
132 /** define the columns size (in point) */
133 void setColsSize(std::vector<float> const &cSize)
134 {
135 m_colsSize=cSize;
136 }
137
138 //! returns the i^th cell
139 std::shared_ptr<MWAWCell> get(int id);
140
141 /** try to build the table structures */
142 bool updateTable();
143 /** returns true if the table has extralines */
144 bool hasExtraLines()
145 {
146 if (!updateTable()) return false;
147 return m_hasExtraLines;
148 }
149
150 /** try to send the table
151
152 Note: either send the table ( and returns true ) or do nothing.
153 */
154 bool sendTable(MWAWListenerPtr listener, bool inFrame=true);
155
156 /** try to send the table as basic text */
157 bool sendAsText(MWAWListenerPtr listener);
158
159 // interface with the content listener
160
161 //! adds the table properties to propList
162 void addTablePropertiesTo(librevenge::RVNGPropertyList &propList) const;
163
164 protected:
165 //! convert a cell position in a posToCellId's position
166 int getCellIdPos(int col, int row) const
167 {
168 if (col<0||col>=int(m_numCols))
169 return -1;
170 if (row<0||row>=int(m_numRows))
171 return -1;
172 return col*int(m_numRows)+row;
173 }
174 //! create the correspondance list, ...
175 bool buildStructures();
176 /** compute the rows and the cells size */
177 bool buildDims();
178 /** a function which fills to posToCellId vector using the cell position */
179 bool buildPosToCellId();
180 //! send extra line
181 void sendExtraLines(MWAWListenerPtr listener) const;
182
183 protected:
184 /** a int to indicate what data are given in entries*/
185 uint32_t m_givenData;
186 /** a int to indicate what data are been reconstruct*/
187 uint32_t m_setData;
188 /** do we need to merge cell borders ( default yes) */
189 bool m_mergeBorders;
190 /** the list of cells */
191 std::vector<std::shared_ptr<MWAWCell> > m_cellsList;
192 /** the number of rows ( set by buildPosToCellId ) */
193 size_t m_numRows;
194 /** the number of cols ( set by buildPosToCellId ) */
195 size_t m_numCols;
196 /** the final row size (in point) */
197 std::vector<float> m_rowsSize;
198 /** the final col size (in point) */
199 std::vector<float> m_colsSize;
200 /** the table alignment */
201 Alignment m_alignment;
202 /** the left margin in point */
203 float m_leftMargin;
204 /** the right margin in point */
205 float m_rightMargin;
206
207 /** a vector used to store an id corresponding to each cell */
208 std::vector<int> m_posToCellId;
209 /** true if we need to send extra lines */
210 bool m_hasExtraLines;
211 };
212
213 #endif
214 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: