MWAWTable.hxx
Go to the documentation of this file.
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 (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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 class MWAWTable;
51 
53 class MWAWTable
54 {
55 public:
57  enum DataSet {
59  };
63  enum Alignment {
65  };
67  MWAWTable(uint32_t givenData=BoxBit) :
68  m_givenData(givenData), m_setData(givenData), m_mergeBorders(true), m_cellsList(),
70  m_posToCellId(), m_hasExtraLines(false) {}
71 
73  virtual ~MWAWTable();
74 
76  void add(shared_ptr<MWAWCell> cell) {
77  if (!cell) {
78  MWAW_DEBUG_MSG(("MWAWTable::add: must be called with a cell\n"));
79  return;
80  }
81  m_cellsList.push_back(cell);
82  }
84  bool mergeBorders() const {
85  return m_mergeBorders;
86  }
88  bool setMergeBorders(bool val) {
89  return m_mergeBorders=val;
90  }
93  void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0) {
94  m_alignment = align;
95  m_leftMargin = leftMargin;
96  m_rightMargin = rightMargin;
97  }
99  int numCells() const {
100  return int(m_cellsList.size());
101  }
103  std::vector<float> const &getRowsSize() const {
104  return m_rowsSize;
105  }
107  void setRowsSize(std::vector<float> const &rSize) {
108  m_rowsSize=rSize;
109  }
111  std::vector<float> const &getColsSize() const {
112  return m_colsSize;
113  }
115  void setColsSize(std::vector<float> const &cSize) {
116  m_colsSize=cSize;
117  }
118 
120  shared_ptr<MWAWCell> get(int id);
121 
123  bool updateTable();
125  bool hasExtraLines() {
126  if (!updateTable()) return false;
127  return m_hasExtraLines;
128  }
129 
134  bool sendTable(MWAWContentListenerPtr listener, bool inFrame=true);
135 
137  bool sendAsText(MWAWContentListenerPtr listener);
138 
139  // interface with the content listener
140 
142  void addTablePropertiesTo(WPXPropertyList &propList, WPXPropertyListVector &columns) const;
143 
144 protected:
146  int getCellIdPos(int col, int row) const {
147  if (col<0||col>=int(m_numCols))
148  return -1;
149  if (row<0||row>=int(m_numRows))
150  return -1;
151  return col*int(m_numRows)+row;
152  }
154  bool buildStructures();
156  bool buildDims();
158  bool buildPosToCellId();
160  void sendExtraLines(MWAWContentListenerPtr listener) const;
161 
162 protected:
164  uint32_t m_givenData;
166  uint32_t m_setData;
170  std::vector<shared_ptr<MWAWCell> > m_cellsList;
172  size_t m_numRows;
174  size_t m_numCols;
176  std::vector<float> m_rowsSize;
178  std::vector<float> m_colsSize;
185 
187  std::vector<int> m_posToCellId;
190 };
191 
192 #endif
Definition: MWAWTable.hxx:64
std::vector< float > const & getRowsSize() const
returns the row size if defined (in point)
Definition: MWAWTable.hxx:103
int getCellIdPos(int col, int row) const
convert a cell position in a posToCellId&#39;s position
Definition: MWAWTable.hxx:146
void setColsSize(std::vector< float > const &cSize)
define the columns size (in point)
Definition: MWAWTable.hxx:115
Definition: MWAWTable.hxx:64
float m_leftMargin
the left margin in point
Definition: MWAWTable.hxx:182
void setRowsSize(std::vector< float > const &rSize)
define the row size (in point)
Definition: MWAWTable.hxx:107
Definition: MWAWTable.hxx:58
void add(shared_ptr< MWAWCell > cell)
add a new cells
Definition: MWAWTable.hxx:76
a class used to recreate the table structure using cell informations, ....
Definition: MWAWTable.hxx:53
Definition: MWAWTable.hxx:58
Definition: MWAWTable.hxx:58
bool updateTable()
try to build the table structures
Definition: MWAWTable.cxx:439
uint32_t m_setData
a int to indicate what data are been reconstruct
Definition: MWAWTable.hxx:166
std::vector< float > const & getColsSize() const
returns the columns size if defined (in point)
Definition: MWAWTable.hxx:111
bool buildPosToCellId()
a function which fills to posToCellId vector using the cell position
Definition: MWAWTable.cxx:296
Definition: MWAWTable.hxx:64
bool m_mergeBorders
do we need to merge cell borders ( default yes)
Definition: MWAWTable.hxx:168
float m_rightMargin
the right margin in point
Definition: MWAWTable.hxx:184
bool m_hasExtraLines
true if we need to send extra lines
Definition: MWAWTable.hxx:189
size_t m_numRows
the number of rows ( set by buildPosToCellId )
Definition: MWAWTable.hxx:172
bool hasExtraLines()
returns true if the table has extralines
Definition: MWAWTable.hxx:125
void sendExtraLines(MWAWContentListenerPtr listener) const
send extra line
Definition: MWAWTable.cxx:154
bool setMergeBorders(bool val)
sets the merge borders&#39; value
Definition: MWAWTable.hxx:88
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:116
bool buildDims()
compute the rows and the cells size
Definition: MWAWTable.cxx:353
Definition: MWAWTable.hxx:58
void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
defines the current alignment
Definition: MWAWTable.hxx:93
virtual ~MWAWTable()
the destructor
Definition: MWAWTable.cxx:106
Alignment
an enum do define the table alignement.
Definition: MWAWTable.hxx:63
uint32_t m_givenData
a int to indicate what data are given in entries
Definition: MWAWTable.hxx:164
bool sendAsText(MWAWContentListenerPtr listener)
try to send the table as basic text
Definition: MWAWTable.cxx:484
std::vector< shared_ptr< MWAWCell > > m_cellsList
the list of cells
Definition: MWAWTable.hxx:170
Alignment m_alignment
the table alignment
Definition: MWAWTable.hxx:180
shared_ptr< MWAWContentListener > MWAWContentListenerPtr
a smart pointer of MWAWContentListener
Definition: libmwaw_internal.hxx:340
bool sendTable(MWAWContentListenerPtr listener, bool inFrame=true)
try to send the table
Definition: MWAWTable.cxx:452
size_t m_numCols
the number of cols ( set by buildPosToCellId )
Definition: MWAWTable.hxx:174
std::vector< float > m_rowsSize
the final row size (in point)
Definition: MWAWTable.hxx:176
std::vector< float > m_colsSize
the final col size (in point)
Definition: MWAWTable.hxx:178
std::vector< int > m_posToCellId
a vector used to store an id corresponding to each cell
Definition: MWAWTable.hxx:187
DataSet
an enum used to indicate what the list of entries which are filled
Definition: MWAWTable.hxx:57
bool buildStructures()
create the correspondance list, ...
Definition: MWAWTable.cxx:206
MWAWTable(uint32_t givenData=BoxBit)
the constructor
Definition: MWAWTable.hxx:67
void addTablePropertiesTo(WPXPropertyList &propList, WPXPropertyListVector &columns) const
adds the table properties to propList
Definition: MWAWTable.cxx:119
bool mergeBorders() const
returns true if we need to merge borders
Definition: MWAWTable.hxx:84
Definition: MWAWTable.hxx:64
Definition: MWAWTable.hxx:58
int numCells() const
returns the number of cell
Definition: MWAWTable.hxx:99

Generated on Tue Mar 10 2015 17:32:09 for libmwaw by doxygen 1.8.5