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(0xFFFFFF) { }
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);
00188
00190 uint32_t backgroundColor() const
00191 {
00192 return m_backgroundColor;
00193 }
00195 void setBackgroundColor(uint32_t color)
00196 {
00197 m_backgroundColor = color;
00198 }
00199
00201 int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const;
00202
00204 friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
00205
00207 struct CompareFormat
00208 {
00210 CompareFormat() {}
00212 bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
00213 {
00214 return c1.compare(c2, true) < 0;
00215 }
00216 };
00217
00218 protected:
00220 static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
00222 WPSFont m_font;
00224 HorizontalAlignment m_hAlign;
00226 VerticalAlignment m_vAlign;
00228 std::vector<WPSBorder> m_bordersList;
00230 FormatType m_format;
00232 int m_subFormat;
00234 std::string m_DTFormat;
00236 int m_digits;
00238 bool m_protected;
00240 uint32_t m_backgroundColor;
00241 };
00242
00243 class WPSTable;
00244
00246 class WPSCell : public WPSCellFormat
00247 {
00248 friend class WPSTable;
00249 public:
00251 WPSCell() : WPSCellFormat(), m_box(), m_verticalSet(true), m_position(0,0), m_numberCellSpanned(1,1) {}
00253 virtual ~WPSCell() {}
00254
00256 void addTo(librevenge::RVNGPropertyList &propList) const;
00257
00259 void setBox(Box2f const &b)
00260 {
00261 m_box = b;
00262 }
00264 Box2f const &box() const
00265 {
00266 return m_box;
00267 }
00269 bool isVerticalSet() const
00270 {
00271 return m_verticalSet;
00272 }
00274 void setVerticalSet(bool verticalSet)
00275 {
00276 m_verticalSet = verticalSet;
00277 }
00279 Vec2i &position()
00280 {
00281 return m_position;
00282 }
00284 Vec2i const &position() const
00285 {
00286 return m_position;
00287 }
00289 void setPosition(Vec2i posi)
00290 {
00291 m_position = posi;
00292 }
00293
00295 Vec2i const &numSpannedCells() const
00296 {
00297 return m_numberCellSpanned;
00298 }
00300 void setNumSpannedCells(Vec2i numSpanned)
00301 {
00302 m_numberCellSpanned=numSpanned;
00303 }
00304
00306 virtual bool send(WPSListenerPtr &listener) = 0;
00307
00309 virtual bool sendContent(WPSListenerPtr &listener) = 0;
00310
00312 friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
00313
00314 protected:
00316 struct Compare
00317 {
00318 Compare(int dim) : m_coord(dim) {}
00320 struct Point
00321 {
00322 Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
00323 float getPos(int coord) const
00324 {
00325 if (m_which)
00326 return m_cell->box().max()[coord];
00327 return m_cell->box().min()[coord];
00328 }
00329 float getSize(int coord) const
00330 {
00331 return m_cell->box().size()[coord];
00332 }
00333 int m_which;
00334 WPSCell const *m_cell;
00335 };
00336
00338 bool operator()(Point const &c1, Point const &c2) const
00339 {
00340 float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
00341 if (diffF < 0) return true;
00342 if (diffF > 0) return false;
00343 int diff = c2.m_which - c1.m_which;
00344 if (diff) return (diff < 0);
00345 diffF = c1.m_cell->box().size()[m_coord]
00346 - c2.m_cell->box().size()[m_coord];
00347 if (diffF < 0) return true;
00348 if (diffF > 0) return false;
00349 if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
00350 #ifdef _WIN64
00351 return ((__int64)c1.m_cell < (__int64)c2.m_cell);
00352 #else
00353 return long(c1.m_cell) < long(c2.m_cell);
00354 #endif
00355 }
00356
00358 int m_coord;
00359 };
00360
00362 Box2f m_box;
00364 bool m_verticalSet;
00366 Vec2i m_position;
00368 Vec2i m_numberCellSpanned;
00369 };
00370
00371 #endif
00372