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 
51 class MWAWTable
52 {
53 public:
55  enum DataSet {
57  };
61  enum Alignment {
63  };
65  MWAWTable(uint32_t givenData=BoxBit) :
66  m_givenData(givenData), m_setData(givenData), m_mergeBorders(true), m_cellsList(),
68  m_posToCellId(), m_hasExtraLines(false) {}
69 
71  virtual ~MWAWTable();
72 
74  void add(shared_ptr<MWAWCell> cell)
75  {
76  if (!cell) {
77  MWAW_DEBUG_MSG(("MWAWTable::add: must be called with a cell\n"));
78  return;
79  }
80  m_cellsList.push_back(cell);
81  }
83  bool mergeBorders() const
84  {
85  return m_mergeBorders;
86  }
88  bool setMergeBorders(bool val)
89  {
90  return m_mergeBorders=val;
91  }
94  void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
95  {
96  m_alignment = align;
97  m_leftMargin = leftMargin;
98  m_rightMargin = rightMargin;
99  }
101  int numCells() const
102  {
103  return int(m_cellsList.size());
104  }
106  std::vector<float> const &getRowsSize() const
107  {
108  return m_rowsSize;
109  }
111  void setRowsSize(std::vector<float> const &rSize)
112  {
113  m_rowsSize=rSize;
114  }
116  std::vector<float> const &getColsSize() const
117  {
118  return m_colsSize;
119  }
121  void setColsSize(std::vector<float> const &cSize)
122  {
123  m_colsSize=cSize;
124  }
125 
127  shared_ptr<MWAWCell> get(int id);
128 
130  bool updateTable();
133  {
134  if (!updateTable()) return false;
135  return m_hasExtraLines;
136  }
137 
142  bool sendTable(MWAWListenerPtr listener, bool inFrame=true);
143 
145  bool sendAsText(MWAWListenerPtr listener);
146 
147  // interface with the content listener
148 
150  void addTablePropertiesTo(librevenge::RVNGPropertyList &propList) const;
151 
152 protected:
154  int getCellIdPos(int col, int row) const
155  {
156  if (col<0||col>=int(m_numCols))
157  return -1;
158  if (row<0||row>=int(m_numRows))
159  return -1;
160  return col*int(m_numRows)+row;
161  }
163  bool buildStructures();
165  bool buildDims();
167  bool buildPosToCellId();
169  void sendExtraLines(MWAWListenerPtr listener) const;
170 
171 protected:
173  uint32_t m_givenData;
175  uint32_t m_setData;
179  std::vector<shared_ptr<MWAWCell> > m_cellsList;
181  size_t m_numRows;
183  size_t m_numCols;
185  std::vector<float> m_rowsSize;
187  std::vector<float> m_colsSize;
194 
196  std::vector<int> m_posToCellId;
199 };
200 
201 #endif
202 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
bool sendAsText(MWAWListenerPtr listener)
try to send the table as basic text
Definition: MWAWTable.cxx:493
shared_ptr< MWAWListener > MWAWListenerPtr
a smart pointer of MWAWListener
Definition: libmwaw_internal.hxx:441
Definition: MWAWTable.hxx:62
std::vector< float > const & getRowsSize() const
returns the row size if defined (in point)
Definition: MWAWTable.hxx:106
int getCellIdPos(int col, int row) const
convert a cell position in a posToCellId's position
Definition: MWAWTable.hxx:154
void setColsSize(std::vector< float > const &cSize)
define the columns size (in point)
Definition: MWAWTable.hxx:121
Definition: MWAWTable.hxx:62
float m_leftMargin
the left margin in point
Definition: MWAWTable.hxx:191
void setRowsSize(std::vector< float > const &rSize)
define the row size (in point)
Definition: MWAWTable.hxx:111
Definition: MWAWTable.hxx:56
void add(shared_ptr< MWAWCell > cell)
add a new cells
Definition: MWAWTable.hxx:74
a class used to recreate the table structure using cell informations, ....
Definition: MWAWTable.hxx:51
Definition: MWAWTable.hxx:56
Definition: MWAWTable.hxx:56
bool updateTable()
try to build the table structures
Definition: MWAWTable.cxx:449
uint32_t m_setData
a int to indicate what data are been reconstruct
Definition: MWAWTable.hxx:175
void addTablePropertiesTo(librevenge::RVNGPropertyList &propList) const
adds the table properties to propList
Definition: MWAWTable.cxx:122
std::vector< float > const & getColsSize() const
returns the columns size if defined (in point)
Definition: MWAWTable.hxx:116
bool buildPosToCellId()
a function which fills to posToCellId vector using the cell position
Definition: MWAWTable.cxx:302
Definition: MWAWTable.hxx:62
bool m_mergeBorders
do we need to merge cell borders ( default yes)
Definition: MWAWTable.hxx:177
float m_rightMargin
the right margin in point
Definition: MWAWTable.hxx:193
bool m_hasExtraLines
true if we need to send extra lines
Definition: MWAWTable.hxx:198
size_t m_numRows
the number of rows ( set by buildPosToCellId )
Definition: MWAWTable.hxx:181
bool hasExtraLines()
returns true if the table has extralines
Definition: MWAWTable.hxx:132
bool setMergeBorders(bool val)
sets the merge borders' value
Definition: MWAWTable.hxx:88
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:127
bool buildDims()
compute the rows and the cells size
Definition: MWAWTable.cxx:359
Definition: MWAWTable.hxx:56
void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
defines the current alignment
Definition: MWAWTable.hxx:94
virtual ~MWAWTable()
the destructor
Definition: MWAWTable.cxx:109
Alignment
an enum do define the table alignment.
Definition: MWAWTable.hxx:61
uint32_t m_givenData
a int to indicate what data are given in entries
Definition: MWAWTable.hxx:173
std::vector< shared_ptr< MWAWCell > > m_cellsList
the list of cells
Definition: MWAWTable.hxx:179
Alignment m_alignment
the table alignment
Definition: MWAWTable.hxx:189
size_t m_numCols
the number of cols ( set by buildPosToCellId )
Definition: MWAWTable.hxx:183
std::vector< float > m_rowsSize
the final row size (in point)
Definition: MWAWTable.hxx:185
Defines MWAWCell (cell content and format)
std::vector< float > m_colsSize
the final col size (in point)
Definition: MWAWTable.hxx:187
std::vector< int > m_posToCellId
a vector used to store an id corresponding to each cell
Definition: MWAWTable.hxx:196
bool sendTable(MWAWListenerPtr listener, bool inFrame=true)
try to send the table
Definition: MWAWTable.cxx:462
DataSet
an enum used to indicate what the list of entries which are filled
Definition: MWAWTable.hxx:55
bool buildStructures()
create the correspondance list, ...
Definition: MWAWTable.cxx:212
MWAWTable(uint32_t givenData=BoxBit)
the constructor
Definition: MWAWTable.hxx:65
bool mergeBorders() const
returns true if we need to merge borders
Definition: MWAWTable.hxx:83
Definition: MWAWTable.hxx:62
Definition: MWAWTable.hxx:56
void sendExtraLines(MWAWListenerPtr listener) const
send extra line
Definition: MWAWTable.cxx:159
int numCells() const
returns the number of cell
Definition: MWAWTable.hxx:101

Generated on Thu Jul 9 2015 20:26:36 for libmwaw by doxygen 1.8.8