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 #ifndef WPS_CELL_H
00030 # define WPS_CELL_H
00031
00032 #include <iostream>
00033 #include <vector>
00034
00035 #include "libwps_internal.h"
00036
00037 #include "WPSFont.h"
00038
00040 class WPSCellFormat
00041 {
00042 public:
00046 enum HorizontalAlignment { HALIGN_LEFT, HALIGN_RIGHT, HALIGN_CENTER,
00047 HALIGN_FULL, HALIGN_DEFAULT
00048 };
00050 enum VerticalAlignment { VALIGN_TOP, VALIGN_CENTER, VALIGN_BOTTOM, VALIGN_DEFAULT };
00051
00053 enum FormatType { F_TEXT, F_BOOLEAN, F_NUMBER, F_DATE, F_TIME, F_UNKNOWN };
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00068 WPSCellFormat() :
00069 m_font(), m_hAlign(HALIGN_DEFAULT), m_vAlign(VALIGN_DEFAULT), m_bordersList(), m_format(F_UNKNOWN), m_subFormat(0), m_DTFormat(""), m_digits(-1000), m_protected(false), m_backgroundColor(WPSColor::white()) { }
00071 virtual ~WPSCellFormat() {}
00073 bool hasBasicFormat() const
00074 {
00075 return m_format==F_TEXT || m_format==F_UNKNOWN;
00076 }
00078 std::string getValueType() const;
00080 void addTo(librevenge::RVNGPropertyList &propList) const;
00082 bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const;
00083
00085 WPSFont const &getFont() const
00086 {
00087 return m_font;
00088 }
00090 void setFont(WPSFont const &font)
00091 {
00092 m_font=font;
00093 }
00095 HorizontalAlignment hAlignement() const
00096 {
00097 return m_hAlign;
00098 }
00100 void setHAlignement(HorizontalAlignment align)
00101 {
00102 m_hAlign = align;
00103 }
00104
00106 VerticalAlignment vAlignement() const
00107 {
00108 return m_vAlign;
00109 }
00111 void setVAlignement(VerticalAlignment align)
00112 {
00113 m_vAlign = align;
00114 }
00115
00117 FormatType getFormat() const
00118 {
00119 return m_format;
00120 }
00122 int getSubFormat() const
00123 {
00124 return m_subFormat;
00125 }
00127 std::string getDTFormat() const
00128 {
00129 return m_DTFormat;
00130 }
00132 void setFormat(FormatType form, int subForm=0)
00133 {
00134 m_format = form;
00135 m_subFormat = subForm;
00136 }
00138 void setDTFormat(FormatType form, std::string const &dtFormat="")
00139 {
00140 m_format = form;
00141 m_subFormat = 0;
00142 m_DTFormat = dtFormat;
00143 }
00144
00146 int digits() const
00147 {
00148 return m_digits;
00149 }
00151 void setDigits(int newDigit)
00152 {
00153 m_digits = newDigit;
00154 }
00155
00157 bool isProtected() const
00158 {
00159 return m_protected;
00160 }
00161
00163 void setProtected(bool fl)
00164 {
00165 m_protected = fl;
00166 }
00167
00169 bool hasBorders() const
00170 {
00171 return m_bordersList.size() != 0;
00172 }
00173
00175 std::vector<WPSBorder> const &borders() const
00176 {
00177 return m_bordersList;
00178 }
00179
00181 void resetBorders()
00182 {
00183 m_bordersList.resize(0);
00184 }
00185
00187 void setBorders(int wh, WPSBorder const &border);
00189 void setBorders(std::vector<WPSBorder> const &newBorders)
00190 {
00191 m_bordersList=newBorders;
00192 }
00193
00195 WPSColor backgroundColor() const
00196 {
00197 return m_backgroundColor;
00198 }
00200 void setBackgroundColor(WPSColor const &color)
00201 {
00202 m_backgroundColor = color;
00203 }
00204
00206 int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const;
00207
00209 friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
00210
00212 struct CompareFormat
00213 {
00215 CompareFormat() {}
00217 bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
00218 {
00219 return c1.compare(c2, true) < 0;
00220 }
00221 };
00222
00223 protected:
00225 static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
00227 WPSFont m_font;
00229 HorizontalAlignment m_hAlign;
00231 VerticalAlignment m_vAlign;
00233 std::vector<WPSBorder> m_bordersList;
00235 FormatType m_format;
00237 int m_subFormat;
00239 std::string m_DTFormat;
00241 int m_digits;
00243 bool m_protected;
00245 WPSColor m_backgroundColor;
00246 };
00247
00248 class WPSTable;
00249
00251 class WPSCell : public WPSCellFormat
00252 {
00253 friend class WPSTable;
00254 public:
00256 WPSCell() : WPSCellFormat(), m_box(), m_verticalSet(true), m_position(0,0), m_numberCellSpanned(1,1) {}
00258 virtual ~WPSCell() {}
00259
00261 void addTo(librevenge::RVNGPropertyList &propList) const;
00262
00264 void setBox(Box2f const &b)
00265 {
00266 m_box = b;
00267 }
00269 Box2f const &box() const
00270 {
00271 return m_box;
00272 }
00274 bool isVerticalSet() const
00275 {
00276 return m_verticalSet;
00277 }
00279 void setVerticalSet(bool verticalSet)
00280 {
00281 m_verticalSet = verticalSet;
00282 }
00284 Vec2i &position()
00285 {
00286 return m_position;
00287 }
00289 Vec2i const &position() const
00290 {
00291 return m_position;
00292 }
00294 void setPosition(Vec2i posi)
00295 {
00296 m_position = posi;
00297 }
00298
00300 Vec2i const &numSpannedCells() const
00301 {
00302 return m_numberCellSpanned;
00303 }
00305 void setNumSpannedCells(Vec2i numSpanned)
00306 {
00307 m_numberCellSpanned=numSpanned;
00308 }
00309
00311 virtual bool send(WPSListenerPtr &listener) = 0;
00312
00314 virtual bool sendContent(WPSListenerPtr &listener) = 0;
00315
00317 friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
00318
00319 protected:
00321 struct Compare
00322 {
00323 Compare(int dim) : m_coord(dim) {}
00325 struct Point
00326 {
00327 Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
00328 float getPos(int coord) const
00329 {
00330 if (m_which)
00331 return m_cell->box().max()[coord];
00332 return m_cell->box().min()[coord];
00333 }
00334 float getSize(int coord) const
00335 {
00336 return m_cell->box().size()[coord];
00337 }
00338 int m_which;
00339 WPSCell const *m_cell;
00340 };
00341
00343 bool operator()(Point const &c1, Point const &c2) const
00344 {
00345 float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
00346 if (diffF < 0) return true;
00347 if (diffF > 0) return false;
00348 int diff = c2.m_which - c1.m_which;
00349 if (diff) return (diff < 0);
00350 diffF = c1.m_cell->box().size()[m_coord]
00351 - c2.m_cell->box().size()[m_coord];
00352 if (diffF < 0) return true;
00353 if (diffF > 0) return false;
00354 if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
00355 #ifdef _WIN64
00356 return ((__int64)c1.m_cell < (__int64)c2.m_cell);
00357 #else
00358 return long(c1.m_cell) < long(c2.m_cell);
00359 #endif
00360 }
00361
00363 int m_coord;
00364 };
00365
00367 Box2f m_box;
00369 bool m_verticalSet;
00371 Vec2i m_position;
00373 Vec2i m_numberCellSpanned;
00374 };
00375
00376 #endif
00377