MWAWTable.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
/*
* Structure to store and construct a table from an unstructured list
* of cell
*
*/
#ifndef MWAW_TABLE
# define MWAW_TABLE
#include <iostream>
#include <vector>
#include "libmwaw_internal.hxx"
#include "MWAWCell.hxx"
class MWAWTable;
class MWAWTable
{
public:
enum DataSet {
CellPositionBit=1, BoxBit=2, SizeBit=4, TableDimBit=8, TablePosToCellBit=0x10
};
enum Alignment {
Paragraph, Left, Center, Right
};
MWAWTable(uint32_t givenData=BoxBit) :
m_givenData(givenData), m_setData(givenData), m_mergeBorders(true), m_cellsList(),
m_numRows(0), m_numCols(0), m_rowsSize(), m_colsSize(), m_alignment(Paragraph), m_leftMargin(0), m_rightMargin(0),
m_posToCellId(), m_hasExtraLines(false) {}
virtual ~MWAWTable();
void add(shared_ptr<MWAWCell> cell) {
if (!cell) {
MWAW_DEBUG_MSG(("MWAWTable::add: must be called with a cell\n"));
return;
}
m_cellsList.push_back(cell);
}
bool mergeBorders() const {
return m_mergeBorders;
}
bool setMergeBorders(bool val) {
return m_mergeBorders=val;
}
void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0) {
m_alignment = align;
m_leftMargin = leftMargin;
m_rightMargin = rightMargin;
}
int numCells() const {
return int(m_cellsList.size());
}
std::vector<float> const &getRowsSize() const {
return m_rowsSize;
}
void setRowsSize(std::vector<float> const &rSize) {
m_rowsSize=rSize;
}
std::vector<float> const &getColsSize() const {
return m_colsSize;
}
void setColsSize(std::vector<float> const &cSize) {
m_colsSize=cSize;
}
shared_ptr<MWAWCell> get(int id);
bool updateTable();
bool hasExtraLines() {
if (!updateTable()) return false;
return m_hasExtraLines;
}
bool sendTable(MWAWContentListenerPtr listener, bool inFrame=true);
bool sendAsText(MWAWContentListenerPtr listener);
// interface with the content listener
void addTablePropertiesTo(WPXPropertyList &propList, WPXPropertyListVector &columns) const;
protected:
int getCellIdPos(int col, int row) const {
if (col<0||col>=int(m_numCols))
return -1;
if (row<0||row>=int(m_numRows))
return -1;
return col*int(m_numRows)+row;
}
bool buildStructures();
bool buildDims();
bool buildPosToCellId();
void sendExtraLines(MWAWContentListenerPtr listener) const;
protected:
uint32_t m_givenData;
uint32_t m_setData;
bool m_mergeBorders;
std::vector<shared_ptr<MWAWCell> > m_cellsList;
size_t m_numRows;
size_t m_numCols;
std::vector<float> m_rowsSize;
std::vector<float> m_colsSize;
Alignment m_alignment;
float m_leftMargin;
float m_rightMargin;
std::vector<int> m_posToCellId;
bool m_hasExtraLines;
};
#endif
MWAWTable::Paragraph
Definition: MWAWTable.hxx:64
MWAWTable::getRowsSize
std::vector< float > const & getRowsSize() const
returns the row size if defined (in point)
Definition: MWAWTable.hxx:103
MWAWTable::getCellIdPos
int getCellIdPos(int col, int row) const
convert a cell position in a posToCellId's position
Definition: MWAWTable.hxx:146
MWAWTable::setColsSize
void setColsSize(std::vector< float > const &cSize)
define the columns size (in point)
Definition: MWAWTable.hxx:115
MWAWTable::Left
Definition: MWAWTable.hxx:64
libmwaw_internal.hxx
MWAWTable::m_leftMargin
float m_leftMargin
the left margin in point
Definition: MWAWTable.hxx:182
MWAWTable::setRowsSize
void setRowsSize(std::vector< float > const &rSize)
define the row size (in point)
Definition: MWAWTable.hxx:107
MWAWTable::TableDimBit
Definition: MWAWTable.hxx:58
MWAWTable::add
void add(shared_ptr< MWAWCell > cell)
add a new cells
Definition: MWAWTable.hxx:76
MWAWTable
a class used to recreate the table structure using cell informations, ....
Definition: MWAWTable.hxx:53
MWAWTable::BoxBit
Definition: MWAWTable.hxx:58
MWAWTable::TablePosToCellBit
Definition: MWAWTable.hxx:58
MWAWTable::updateTable
bool updateTable()
try to build the table structures
Definition: MWAWTable.cxx:446
MWAWTable::m_setData
uint32_t m_setData
a int to indicate what data are been reconstruct
Definition: MWAWTable.hxx:166
MWAWTable::getColsSize
std::vector< float > const & getColsSize() const
returns the columns size if defined (in point)
Definition: MWAWTable.hxx:111
MWAWTable::buildPosToCellId
bool buildPosToCellId()
a function which fills to posToCellId vector using the cell position
Definition: MWAWTable.cxx:303
MWAWTable::Right
Definition: MWAWTable.hxx:64
MWAWTable::m_mergeBorders
bool m_mergeBorders
do we need to merge cell borders ( default yes)
Definition: MWAWTable.hxx:168
MWAWTable::m_rightMargin
float m_rightMargin
the right margin in point
Definition: MWAWTable.hxx:184
MWAWTable::m_hasExtraLines
bool m_hasExtraLines
true if we need to send extra lines
Definition: MWAWTable.hxx:189
MWAWTable::m_numRows
size_t m_numRows
the number of rows ( set by buildPosToCellId )
Definition: MWAWTable.hxx:172
MWAWTable::hasExtraLines
bool hasExtraLines()
returns true if the table has extralines
Definition: MWAWTable.hxx:125
MWAWTable::sendExtraLines
void sendExtraLines(MWAWContentListenerPtr listener) const
send extra line
Definition: MWAWTable.cxx:153
MWAWTable::setMergeBorders
bool setMergeBorders(bool val)
sets the merge borders' value
Definition: MWAWTable.hxx:88
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:111
MWAWTable::buildDims
bool buildDims()
compute the rows and the cells size
Definition: MWAWTable.cxx:360
MWAWTable::CellPositionBit
Definition: MWAWTable.hxx:58
MWAWTable::setAlignment
void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
defines the current alignment
Definition: MWAWTable.hxx:93
MWAWTable::~MWAWTable
virtual ~MWAWTable()
the destructor
Definition: MWAWTable.cxx:105
MWAWTable::Alignment
Alignment
an enum do define the table alignement.
Definition: MWAWTable.hxx:63
MWAWTable::m_givenData
uint32_t m_givenData
a int to indicate what data are given in entries
Definition: MWAWTable.hxx:164
MWAWTable::sendAsText
bool sendAsText(MWAWContentListenerPtr listener)
try to send the table as basic text
Definition: MWAWTable.cxx:491
MWAWTable::m_cellsList
std::vector< shared_ptr< MWAWCell > > m_cellsList
the list of cells
Definition: MWAWTable.hxx:170
MWAWTable::m_alignment
Alignment m_alignment
the table alignment
Definition: MWAWTable.hxx:180
MWAWContentListenerPtr
shared_ptr< MWAWContentListener > MWAWContentListenerPtr
a smart pointer of MWAWContentListener
Definition: libmwaw_internal.hxx:330
MWAWTable::sendTable
bool sendTable(MWAWContentListenerPtr listener, bool inFrame=true)
try to send the table
Definition: MWAWTable.cxx:459
MWAWTable::m_numCols
size_t m_numCols
the number of cols ( set by buildPosToCellId )
Definition: MWAWTable.hxx:174
MWAWTable::m_rowsSize
std::vector< float > m_rowsSize
the final row size (in point)
Definition: MWAWTable.hxx:176
MWAWCell.hxx
MWAWTable::m_colsSize
std::vector< float > m_colsSize
the final col size (in point)
Definition: MWAWTable.hxx:178
MWAWTable::m_posToCellId
std::vector< int > m_posToCellId
a vector used to store an id corresponding to each cell
Definition: MWAWTable.hxx:187
MWAWTable::DataSet
DataSet
an enum used to indicate what the list of entries which are filled
Definition: MWAWTable.hxx:57
MWAWTable::buildStructures
bool buildStructures()
create the correspondance list, ...
Definition: MWAWTable.cxx:213
MWAWTable::MWAWTable
MWAWTable(uint32_t givenData=BoxBit)
the constructor
Definition: MWAWTable.hxx:67
MWAWTable::addTablePropertiesTo
void addTablePropertiesTo(WPXPropertyList &propList, WPXPropertyListVector &columns) const
adds the table properties to propList
Definition: MWAWTable.cxx:118
MWAWTable::mergeBorders
bool mergeBorders() const
returns true if we need to merge borders
Definition: MWAWTable.hxx:84
MWAWTable::Center
Definition: MWAWTable.hxx:64
MWAWTable::SizeBit
Definition: MWAWTable.hxx:58
MWAWTable::numCells
int numCells() const
returns the number of cell
Definition: MWAWTable.hxx:99