MWAWTable.hxx Source File documentation

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 {
56 CellPositionBit=1, BoxBit=2, SizeBit=4, TableDimBit=8, TablePosToCellBit=0x10
57 };
61 enum Alignment {
62 Paragraph, Left, Center, Right
63 };
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
83 virtual ~MWAWTable();
84
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 }
95 bool mergeBorders() const
96 {
97 return m_mergeBorders;
98 }
100 bool setMergeBorders(bool val)
101 {
102 return m_mergeBorders=val;
103 }
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 }
113 int numCells() const
114 {
115 return int(m_cellsList.size());
116 }
118 std::vector<float> const &getRowsSize() const
119 {
120 return m_rowsSize;
121 }
123 void setRowsSize(std::vector<float> const &rSize)
124 {
125 m_rowsSize=rSize;
126 }
128 std::vector<float> const &getColsSize() const
129 {
130 return m_colsSize;
131 }
133 void setColsSize(std::vector<float> const &cSize)
134 {
135 m_colsSize=cSize;
136 }
137
139 std::shared_ptr<MWAWCell> get(int id);
140
142 bool updateTable();
144 bool hasExtraLines()
145 {
146 if (!updateTable()) return false;
147 return m_hasExtraLines;
148 }
149
154 bool sendTable(MWAWListenerPtr listener, bool inFrame=true);
155
157 bool sendAsText(MWAWListenerPtr listener);
158
159 // interface with the content listener
160
162 void addTablePropertiesTo(librevenge::RVNGPropertyList &propList) const;
163
164 protected:
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 }
175 bool buildStructures();
177 bool buildDims();
179 bool buildPosToCellId();
181 void sendExtraLines(MWAWListenerPtr listener) const;
182
183 protected:
185 uint32_t m_givenData;
187 uint32_t m_setData;
189 bool m_mergeBorders;
191 std::vector<std::shared_ptr<MWAWCell> > m_cellsList;
193 size_t m_numRows;
195 size_t m_numCols;
197 std::vector<float> m_rowsSize;
199 std::vector<float> m_colsSize;
201 Alignment m_alignment;
203 float m_leftMargin;
205 float m_rightMargin;
206
208 std::vector<int> m_posToCellId;
210 bool m_hasExtraLines;
211 };
212
213 #endif
214 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWTable::numCells
int numCells() const
returns the number of cell
Definition: MWAWTable.hxx:113
MWAWTable::buildPosToCellId
bool buildPosToCellId()
a function which fills to posToCellId vector using the cell position
Definition: MWAWTable.cxx:312
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:842
MWAWTable::Paragraph
@ Paragraph
Definition: MWAWTable.hxx:62
MWAWTableInternal::Compare::Point::m_cellId
int m_cellId
the cell id ( used by compare)
Definition: MWAWTable.cxx:90
MWAWPosition::setRelativePosition
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: MWAWPosition.hxx:237
MWAWTableInternal::Compare::Point::getSize
float getSize(int coord) const
returns the cells size
Definition: MWAWTable.cxx:81
MWAWTable::BoxBit
@ BoxBit
Definition: MWAWTable.hxx:56
MWAWTableInternal::Compare::Point
small structure to define a cell point
Definition: MWAWTable.cxx:67
MWAWTable.hxx
MWAWTableInternal::Compare::Compare
Compare(int dim)
constructor
Definition: MWAWTable.cxx:62
MWAWTable::sendTable
bool sendTable(MWAWListenerPtr listener, bool inFrame=true)
try to send the table
Definition: MWAWTable.cxx:471
MWAWTable::m_givenData
uint32_t m_givenData
a int to indicate what data are given in entries
Definition: MWAWTable.hxx:185
MWAWGraphicShape::line
static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a line
Definition: MWAWGraphicShape.cxx:228
MWAWTable::m_leftMargin
float m_leftMargin
the left margin in point
Definition: MWAWTable.hxx:203
MWAWBorder::m_width
double m_width
the border total width in point
Definition: libmwaw_internal.hxx:387
MWAWTable::sendExtraLines
void sendExtraLines(MWAWListenerPtr listener) const
send extra line
Definition: MWAWTable.cxx:170
MWAWBox2::setMin
void setMin(MWAWVec2< T > const &x)
resets the minimum point
Definition: libmwaw_internal.hxx:1085
MWAWTable::getColsSize
std::vector< float > const & getColsSize() const
returns the columns size if defined (in point)
Definition: MWAWTable.hxx:128
MWAWGraphicStyle
a structure used to define a picture style
Definition: MWAWGraphicStyle.hxx:48
MWAWPosition::setOrder
void setOrder(int ord) const
set background/foward order
Definition: MWAWPosition.hxx:264
MWAWCell::hasExtraLine
bool hasExtraLine() const
returns true if we have some extra lines
Definition: MWAWCell.hxx:337
MWAWCell::extraLine
ExtraLine extraLine() const
returns the extra lines
Definition: MWAWCell.hxx:342
MWAWCell.hxx
Defines MWAWCell (cell content and format)
MWAWTable::TableDimBit
@ TableDimBit
Definition: MWAWTable.hxx:56
MWAWTableInternal::Compare::Point::Point
Point(int wh, MWAWCell const *cell, int cellId)
Definition: MWAWTable.cxx:68
MWAWTableInternal::Compare
a comparaison structure used retrieve the rows and the columns
Definition: MWAWTable.cxx:60
MWAWTable::m_hasExtraLines
bool m_hasExtraLines
true if we need to send extra lines
Definition: MWAWTable.hxx:210
MWAWTableInternal::Compare::Point::m_cell
MWAWCell const * m_cell
the cell
Definition: MWAWTable.cxx:88
MWAWTable::Alignment
Alignment
an enum do define the table alignment.
Definition: MWAWTable.hxx:61
MWAWTable::Center
@ Center
Definition: MWAWTable.hxx:62
libmwaw_internal.hxx
MWAWGraphicStyle::m_lineWidth
float m_lineWidth
the linewidth
Definition: MWAWGraphicStyle.hxx:508
MWAWPosition.hxx
MWAWTable::getCellIdPos
int getCellIdPos(int col, int row) const
convert a cell position in a posToCellId's position
Definition: MWAWTable.hxx:166
MWAWTable::setMergeBorders
bool setMergeBorders(bool val)
sets the merge borders' value
Definition: MWAWTable.hxx:100
MWAWTable::hasExtraLines
bool hasExtraLines()
returns true if the table has extralines
Definition: MWAWTable.hxx:144
MWAWTable::m_setData
uint32_t m_setData
a int to indicate what data are been reconstruct
Definition: MWAWTable.hxx:187
MWAWPosition
Class to define the position of an object (textbox, picture, ..) in the document.
Definition: MWAWPosition.hxx:48
MWAWBorder
a border
Definition: libmwaw_internal.hxx:333
MWAWTable::mergeBorders
bool mergeBorders() const
returns true if we need to merge borders
Definition: MWAWTable.hxx:95
MWAWTable::Right
@ Right
Definition: MWAWTable.hxx:62
MWAWPosition::m_wrapping
Wrapping m_wrapping
Wrapping.
Definition: MWAWPosition.hxx:278
MWAWTable::m_posToCellId
std::vector< int > m_posToCellId
a vector used to store an id corresponding to each cell
Definition: MWAWTable.hxx:208
MWAWTable
a class used to recreate the table structure using cell informations, ....
Definition: MWAWTable.hxx:52
MWAWTable::getRowsSize
std::vector< float > const & getRowsSize() const
returns the row size if defined (in point)
Definition: MWAWTable.hxx:118
MWAWVec2< int >
MWAWBox2::setMax
void setMax(MWAWVec2< T > const &y)
resets the maximum point
Definition: libmwaw_internal.hxx:1090
MWAWGraphicShape.hxx
MWAWTable::m_cellsList
std::vector< std::shared_ptr< MWAWCell > > m_cellsList
the list of cells
Definition: MWAWTable.hxx:191
MWAWTable::m_mergeBorders
bool m_mergeBorders
do we need to merge cell borders ( default yes)
Definition: MWAWTable.hxx:189
MWAWTable::setColsSize
void setColsSize(std::vector< float > const &cSize)
define the columns size (in point)
Definition: MWAWTable.hxx:133
MWAWTableInternal::Compare::Point::getPos
float getPos(int coord) const
Definition: MWAWTable.cxx:74
MWAWTable::updateTable
bool updateTable()
try to build the table structures
Definition: MWAWTable.cxx:458
MWAWGraphicStyle::m_lineColor
MWAWColor m_lineColor
the line color
Definition: MWAWGraphicStyle.hxx:516
MWAWTable::setRowsSize
void setRowsSize(std::vector< float > const &rSize)
define the row size (in point)
Definition: MWAWTable.hxx:123
MWAWTable::TablePosToCellBit
@ TablePosToCellBit
Definition: MWAWTable.hxx:56
MWAWCell::extraLineType
MWAWBorder const & extraLineType() const
returns the extra line border
Definition: MWAWCell.hxx:347
MWAWCell::E_Cross
@ E_Cross
Definition: MWAWCell.hxx:137
MWAWTable::m_rowsSize
std::vector< float > m_rowsSize
the final row size (in point)
Definition: MWAWTable.hxx:197
MWAWGraphicStyle.hxx
MWAWTable::SizeBit
@ SizeBit
Definition: MWAWTable.hxx:56
MWAWTable::MWAWTable
MWAWTable(uint32_t givenData=BoxBit)
the constructor
Definition: MWAWTable.hxx:65
MWAWCell::E_Line1
@ E_Line1
Definition: MWAWCell.hxx:137
MWAWPosition::WForeground
@ WForeground
Definition: MWAWPosition.hxx:53
MWAWTable::Left
@ Left
Definition: MWAWTable.hxx:62
MWAWTable::buildStructures
bool buildStructures()
create the correspondance list, ...
Definition: MWAWTable.cxx:223
MWAWBox2::min
MWAWVec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libmwaw_internal.hxx:1039
MWAWTable::m_numCols
size_t m_numCols
the number of cols ( set by buildPosToCellId )
Definition: MWAWTable.hxx:195
MWAWTable::buildDims
bool buildDims()
compute the rows and the cells size
Definition: MWAWTable.cxx:368
MWAWListener.hxx
MWAWTableInternal
Internal: the structures of a MWAWTable.
Definition: MWAWTable.cxx:58
MWAWTable::sendAsText
bool sendAsText(MWAWListenerPtr listener)
try to send the table as basic text
Definition: MWAWTable.cxx:502
MWAWBox2::size
MWAWVec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:1067
MWAWTable::m_numRows
size_t m_numRows
the number of rows ( set by buildPosToCellId )
Definition: MWAWTable.hxx:193
MWAWPosition::Frame
@ Frame
Definition: MWAWPosition.hxx:51
MWAWTable::m_alignment
Alignment m_alignment
the table alignment
Definition: MWAWTable.hxx:201
MWAWTableInternal::Compare::m_coord
int m_coord
the coord to compare
Definition: MWAWTable.cxx:109
MWAWTableInternal::Compare::Point::m_which
int m_which
the position of the point in the cell (0: LT, 1: RB)
Definition: MWAWTable.cxx:86
MWAWListenerPtr
std::shared_ptr< MWAWListener > MWAWListenerPtr
a smart pointer of MWAWListener
Definition: libmwaw_internal.hxx:553
MWAWTable::m_rightMargin
float m_rightMargin
the right margin in point
Definition: MWAWTable.hxx:205
MWAWCell::E_Line2
@ E_Line2
Definition: MWAWCell.hxx:137
MWAWTable::get
std::shared_ptr< MWAWCell > get(int id)
returns the i^th cell
Definition: MWAWTable.cxx:122
MWAWBox2< float >
MWAWCell
a structure used to define a cell and its format
Definition: MWAWCell.hxx:53
MWAWBox2::max
MWAWVec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libmwaw_internal.hxx:1044
MWAWTable::m_colsSize
std::vector< float > m_colsSize
the final col size (in point)
Definition: MWAWTable.hxx:199
MWAWBorder::m_color
MWAWColor m_color
the border color
Definition: libmwaw_internal.hxx:393
MWAWTable::setAlignment
void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
defines the current alignment
Definition: MWAWTable.hxx:106
MWAWTable::addTablePropertiesTo
void addTablePropertiesTo(librevenge::RVNGPropertyList &propList) const
adds the table properties to propList
Definition: MWAWTable.cxx:131
MWAWTable::~MWAWTable
virtual ~MWAWTable()
the destructor
Definition: MWAWTable.cxx:118
MWAWVec2i
MWAWVec2< int > MWAWVec2i
MWAWVec2 of int.
Definition: libmwaw_internal.hxx:838
MWAWCell::bdBox
MWAWBox2f const & bdBox() const
bdbox accessor
Definition: MWAWCell.hxx:206
MWAWTable::add
void add(std::shared_ptr< MWAWCell > cell)
add a new cells
Definition: MWAWTable.hxx:86
MWAWTableInternal::Compare::operator()
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: MWAWTable.cxx:94
MWAWTable::DataSet
DataSet
an enum used to indicate what the list of entries which are filled
Definition: MWAWTable.hxx:55
MWAWTable::CellPositionBit
@ CellPositionBit
Definition: MWAWTable.hxx:56