Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef WPS_CELL_H
00034 # define WPS_CELL_H
00035
00036 #include <iostream>
00037
00038 #include "libwps_internal.h"
00039
00040 class WPXPropertyList;
00041 class WPSContentListener;
00042 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
00043
00045 class WPSCellFormat
00046 {
00047 public:
00051 enum HorizontalAlignment { HALIGN_LEFT, HALIGN_RIGHT, HALIGN_CENTER,
00052 HALIGN_FULL, HALIGN_DEFAULT
00053 };
00055 WPSCellFormat() :
00056 m_hAlign(HALIGN_DEFAULT), m_bordersList(0) { }
00057
00058 virtual ~WPSCellFormat() {}
00059
00060
00062 HorizontalAlignment hAlignement() const
00063 {
00064 return m_hAlign;
00065 }
00067 void setHAlignement(HorizontalAlignment align)
00068 {
00069 m_hAlign = align;
00070 }
00071
00073 bool hasBorders() const
00074 {
00075 return m_bordersList != 0;
00076 }
00078 int borders() const
00079 {
00080 return m_bordersList;
00081 }
00083 void setBorders(int bList)
00084 {
00085 m_bordersList = bList;
00086 }
00087
00089 int compare(WPSCellFormat const &cell) const;
00090
00092 friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
00093
00094 protected:
00096 HorizontalAlignment m_hAlign;
00098 int m_bordersList;
00099 };
00100
00101 class WPSTable;
00102
00104 class WPSCell : public WPSCellFormat
00105 {
00106 friend class WPSTable;
00107 public:
00109 WPSCell() : WPSCellFormat(), m_box(), m_position(0,0), m_numberCellSpanned(1,1) {}
00110
00112 void setBox(Box2f const &b)
00113 {
00114 m_box = b;
00115 }
00117 Box2f const &box() const
00118 {
00119 return m_box;
00120 }
00122 Vec2i &position()
00123 {
00124 return m_position;
00125 }
00127 Vec2i const &position() const
00128 {
00129 return m_position;
00130 }
00132 void setPosition(Vec2i posi)
00133 {
00134 m_position = posi;
00135 }
00136
00138 Vec2i const &numSpannedCells() const
00139 {
00140 return m_numberCellSpanned;
00141 }
00143 void setNumSpannedCells(Vec2i numSpanned)
00144 {
00145 m_numberCellSpanned=numSpanned;
00146 }
00147
00149 virtual bool send(WPSContentListenerPtr &listener) = 0;
00150
00152 virtual bool sendContent(WPSContentListenerPtr &listener) = 0;
00153
00155 friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
00156
00157 protected:
00159 struct Compare
00160 {
00161 Compare(int dim) : m_coord(dim) {}
00163 struct Point
00164 {
00165 Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
00166 float getPos(int coord) const
00167 {
00168 if (m_which)
00169 return m_cell->box().max()[coord];
00170 return m_cell->box().min()[coord];
00171 }
00172 float getSize(int coord) const
00173 {
00174 return m_cell->box().size()[coord];
00175 }
00176 int m_which;
00177 WPSCell const *m_cell;
00178 };
00179
00181 bool operator()(Point const &c1, Point const &c2) const
00182 {
00183 float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
00184 if (diffF) return (diffF < 0);
00185 int diff = c2.m_which - c1.m_which;
00186 if (diff) return (diff < 0);
00187 diffF = c1.m_cell->box().size()[m_coord]
00188 - c2.m_cell->box().size()[m_coord];
00189 if (diffF) return (diffF < 0);
00190 return long(c1.m_cell) < long(c2.m_cell);
00191 }
00192
00194 int m_coord;
00195 };
00196
00198 Box2f m_box;
00200 Vec2i m_position;
00202 Vec2i m_numberCellSpanned;
00203 };
00204
00205 typedef shared_ptr<WPSCell> WPSCellPtr;
00206
00207 #endif
00208