WPSCell.h
Go to the documentation of this file.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* libwps
* Version: MPL 2.0 / LGPLv2.1+
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Major Contributor(s):
* Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
*
* 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.1 or later
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
* applicable instead of those above.
*
* For further information visit http://libwps.sourceforge.net
*/
/* Define some classes used to store a Cell
*/
#ifndef WPS_CELL_H
# define WPS_CELL_H
#include <iostream>
#include <vector>
#include "libwps_internal.h"
class WPXPropertyList;
class WPSContentListener;
typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
class WPSCellFormat
{
public:
enum HorizontalAlignment { HALIGN_LEFT, HALIGN_RIGHT, HALIGN_CENTER,
HALIGN_FULL, HALIGN_DEFAULT
};
WPSCellFormat() :
m_hAlign(HALIGN_DEFAULT), m_bordersList(), m_backgroundColor(0xFFFFFF) { }
virtual ~WPSCellFormat() {}
HorizontalAlignment hAlignement() const
{
return m_hAlign;
}
void setHAlignement(HorizontalAlignment align)
{
m_hAlign = align;
}
bool hasBorders() const
{
return m_bordersList.size() != 0;
}
std::vector<WPSBorder> const &borders() const
{
return m_bordersList;
}
void resetBorders()
{
m_bordersList.resize(0);
}
void setBorders(int wh, WPSBorder const &border);
uint32_t backgroundColor() const
{
return m_backgroundColor;
}
void setBackgroundColor(uint32_t color)
{
m_backgroundColor = color;
}
int compare(WPSCellFormat const &cell) const;
friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
protected:
HorizontalAlignment m_hAlign;
std::vector<WPSBorder> m_bordersList;
uint32_t m_backgroundColor;
};
class WPSTable;
class WPSCell : public WPSCellFormat
{
friend class WPSTable;
public:
WPSCell() : WPSCellFormat(), m_box(), m_verticalSet(true), m_position(0,0), m_numberCellSpanned(1,1) {}
void setBox(Box2f const &b)
{
m_box = b;
}
Box2f const &box() const
{
return m_box;
}
bool isVerticalSet() const
{
return m_verticalSet;
}
void setVerticalSet(bool verticalSet)
{
m_verticalSet = verticalSet;
}
Vec2i &position()
{
return m_position;
}
Vec2i const &position() const
{
return m_position;
}
void setPosition(Vec2i posi)
{
m_position = posi;
}
Vec2i const &numSpannedCells() const
{
return m_numberCellSpanned;
}
void setNumSpannedCells(Vec2i numSpanned)
{
m_numberCellSpanned=numSpanned;
}
virtual bool send(WPSContentListenerPtr &listener) = 0;
virtual bool sendContent(WPSContentListenerPtr &listener) = 0;
friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
protected:
struct Compare
{
Compare(int dim) : m_coord(dim) {}
struct Point
{
Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
float getPos(int coord) const
{
if (m_which)
return m_cell->box().max()[coord];
return m_cell->box().min()[coord];
}
float getSize(int coord) const
{
return m_cell->box().size()[coord];
}
int m_which;
WPSCell const *m_cell;
};
bool operator()(Point const &c1, Point const &c2) const
{
float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
if (diffF < 0) return true;
if (diffF > 0) return false;
int diff = c2.m_which - c1.m_which;
if (diff) return (diff < 0);
diffF = c1.m_cell->box().size()[m_coord]
- c2.m_cell->box().size()[m_coord];
if (diffF < 0) return true;
if (diffF > 0) return false;
if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
return long(c1.m_cell) < long(c2.m_cell);
}
int m_coord;
};
Box2f m_box;
bool m_verticalSet;
Vec2i m_position;
Vec2i m_numberCellSpanned;
};
typedef shared_ptr<WPSCell> WPSCellPtr;
#endif
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */