WPSCell.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3  * Version: MPL 2.0 / LGPLv2.1+
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Major Contributor(s):
10  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11  * Copyright (C) 2006, 2007 Andrew Ziem
12  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15  *
16  * For minor contributions see the git repository.
17  *
18  * Alternatively, the contents of this file may be used under the terms
19  * of the GNU Lesser General Public License Version 2.1 or later
20  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21  * applicable instead of those above.
22  *
23  * For further information visit http://libwps.sourceforge.net
24  */
25 
26 /* Define some classes used to store a Cell
27  */
28 
29 #ifndef WPS_CELL_H
30 # define WPS_CELL_H
31 
32 #include <iostream>
33 #include <vector>
34 
35 #include "libwps_internal.h"
36 
37 #include "WPSFont.h"
38 
41 {
42 public:
48  };
55 
56  /* subformat:
57  NUMBER DATE TIME TEXT
58  0 : default default[3/2/2000] default[10:03:00] default
59  1 : decimal
60  2 : exponential
61  3 : percent
62  4 : money
63  5 : thousand
64  6 : fixed
65  7 : fraction
66  */
67 
70  : m_font()
74  , m_rotation(0)
75  , m_bordersList()
77  , m_subFormat(0)
78  , m_DTFormat("")
79  , m_digits(-1000)
80  , m_protected(false)
81  , m_backgroundColor(WPSColor::white()) { }
82  WPSCellFormat(WPSCellFormat const &)=default;
85  virtual ~WPSCellFormat();
87  bool hasBasicFormat() const
88  {
89  return m_format==F_TEXT || m_format==F_UNKNOWN;
90  }
92  std::string getValueType() const;
94  void addTo(librevenge::RVNGPropertyList &propList) const;
96  bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const;
97 
99  WPSFont const &getFont() const
100  {
101  return m_font;
102  }
104  void setFont(WPSFont const &font)
105  {
106  m_font=font;
107  }
110  {
111  return m_hAlign;
112  }
115  {
116  m_hAlign = align;
117  }
118 
121  {
122  return m_vAlign;
123  }
126  {
127  m_vAlign = align;
128  }
131  {
132  return m_wrapping;
133  }
135  void setWrapping(Wrapping align)
136  {
137  m_wrapping = align;
138  }
139 
141  int getTextRotation() const
142  {
143  return m_rotation;
144  }
146  void setTextRotation(int rotation)
147  {
148  m_rotation = rotation;
149  }
150 
153  {
154  return m_format;
155  }
157  int getSubFormat() const
158  {
159  return m_subFormat;
160  }
162  std::string getDTFormat() const
163  {
164  return m_DTFormat;
165  }
167  void setFormat(FormatType form, int subForm=0)
168  {
169  m_format = form;
170  m_subFormat = subForm;
171  }
173  void setDTFormat(FormatType form, std::string const &dtFormat="")
174  {
175  m_format = form;
176  m_subFormat = 0;
177  m_DTFormat = dtFormat;
178  }
179 
181  int digits() const
182  {
183  return m_digits;
184  }
186  void setDigits(int newDigit)
187  {
188  m_digits = newDigit;
189  }
190 
192  bool isProtected() const
193  {
194  return m_protected;
195  }
196 
198  void setProtected(bool fl)
199  {
200  m_protected = fl;
201  }
202 
204  bool hasBorders() const
205  {
206  return m_bordersList.size() != 0;
207  }
208 
210  std::vector<WPSBorder> const &borders() const
211  {
212  return m_bordersList;
213  }
214 
217  {
218  m_bordersList.resize(0);
219  }
220 
222  void setBorders(int wh, WPSBorder const &border);
224  void setBorders(std::vector<WPSBorder> const &newBorders)
225  {
226  m_bordersList=newBorders;
227  }
228 
231  {
232  return m_backgroundColor;
233  }
235  void setBackgroundColor(WPSColor const &color)
236  {
237  m_backgroundColor = color;
238  }
239 
241  int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const;
242 
244  friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
245 
248  {
252  bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
253  {
254  return c1.compare(c2, true) < 0;
255  }
256  };
257 
258 protected:
260  static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
272  std::vector<WPSBorder> m_bordersList;
278  std::string m_DTFormat;
280  int m_digits;
285 };
286 
287 class WPSTable;
288 
290 class WPSCell : public WPSCellFormat
291 {
292  friend class WPSTable;
293 public:
296  : WPSCellFormat()
297  , m_box()
298  , m_verticalSet(true)
299  , m_position(0,0)
300  , m_numberCellSpanned(1,1) {}
301  WPSCell(WPSCell const &)=default;
302  WPSCell &operator=(WPSCell const &)=default;
304  ~WPSCell() override;
305 
307  void addTo(librevenge::RVNGPropertyList &propList) const;
308 
310  void setBox(WPSBox2f const &b)
311  {
312  m_box = b;
313  }
315  WPSBox2f const &box() const
316  {
317  return m_box;
318  }
320  bool isVerticalSet() const
321  {
322  return m_verticalSet;
323  }
325  void setVerticalSet(bool verticalSet)
326  {
327  m_verticalSet = verticalSet;
328  }
331  {
332  return m_position;
333  }
335  Vec2i const &position() const
336  {
337  return m_position;
338  }
340  void setPosition(Vec2i posi)
341  {
342  m_position = posi;
343  }
344 
346  Vec2i const &numSpannedCells() const
347  {
348  return m_numberCellSpanned;
349  }
351  void setNumSpannedCells(Vec2i numSpanned)
352  {
353  m_numberCellSpanned=numSpanned;
354  }
355 
357  virtual bool send(WPSListenerPtr &listener) = 0;
358 
360  virtual bool sendContent(WPSListenerPtr &listener) = 0;
361 
363  friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
364 
365 protected:
367  struct Compare
368  {
369  explicit Compare(int dim)
370  : m_coord(dim) {}
372  struct Point
373  {
374  Point(int wh, WPSCell const *cell)
375  : m_which(wh)
376  , m_cell(cell) {}
377  float getPos(int coord) const
378  {
379  if (m_which)
380  return m_cell->box().max()[coord];
381  return m_cell->box().min()[coord];
382  }
383  float getSize(int coord) const
384  {
385  return m_cell->box().size()[coord];
386  }
387  int m_which;
388  WPSCell const *m_cell;
389  };
390 
392  bool operator()(Point const &c1, Point const &c2) const
393  {
394  float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
395  if (diffF < 0) return true;
396  if (diffF > 0) return false;
397  int diff = c2.m_which - c1.m_which;
398  if (diff) return (diff < 0);
399  diffF = c1.m_cell->box().size()[m_coord]
400  - c2.m_cell->box().size()[m_coord];
401  if (diffF < 0) return true;
402  if (diffF > 0) return false;
403  if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
404 #ifdef _WIN64
405  return ((__int64)c1.m_cell < (__int64)c2.m_cell);
406 #else
407  return long(c1.m_cell) < long(c2.m_cell);
408 #endif
409  }
410 
412  int m_coord;
413  };
414 
423 };
424 
425 #endif
426 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSCell::Compare::Point::m_cell
WPSCell const * m_cell
Definition: WPSCell.h:388
WPSCellFormat::VALIGN_DEFAULT
@ VALIGN_DEFAULT
Definition: WPSCell.h:50
WPSCellFormat::F_BOOLEAN
@ F_BOOLEAN
Definition: WPSCell.h:54
WPSCell::WPSCell
WPSCell(WPSCell const &)=default
WPSCellFormat::m_subFormat
int m_subFormat
the sub format
Definition: WPSCell.h:276
WPSCellFormat::FormatType
FormatType
the different types of cell's field
Definition: WPSCell.h:54
WPSCell::~WPSCell
~WPSCell() override
destructor
Definition: WPSCell.cpp:530
WPSCellFormat::convertDTFormat
static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector)
convert a DTFormat in a propertyList
Definition: WPSCell.cpp:39
WPSCellFormat::HALIGN_FULL
@ HALIGN_FULL
Definition: WPSCell.h:47
WPSCellFormat::VALIGN_CENTER
@ VALIGN_CENTER
Definition: WPSCell.h:50
WPSCellFormat::CompareFormat::operator()
bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
comparaison function
Definition: WPSCell.h:252
WPSCell::WPSCell
WPSCell()
constructor
Definition: WPSCell.h:295
WPSBorder::Top
@ Top
Definition: libwps_internal.h:400
WPSCellFormat::WRAP_WRAP
@ WRAP_WRAP
Definition: WPSCell.h:52
WPSCell.h
WPSCellFormat::setVAlignment
void setVAlignment(VerticalAlignment align)
sets the vertical alignement
Definition: WPSCell.h:125
WPSCell::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSCell const &cell)
operator<<
Definition: WPSCell.cpp:545
WPSCellFormat::WRAP_DEFAULT
@ WRAP_DEFAULT
Definition: WPSCell.h:52
WPSCellFormat::getFormat
FormatType getFormat() const
returns the format type
Definition: WPSCell.h:152
WPSCellFormat::m_wrapping
Wrapping m_wrapping
the wrapping : by default nothing
Definition: WPSCell.h:268
WPSCellFormat::operator=
WPSCellFormat & operator=(WPSCellFormat const &)=default
WPSCellFormat::HALIGN_DEFAULT
@ HALIGN_DEFAULT
Definition: WPSCell.h:47
WPSBorder::BottomBit
@ BottomBit
Definition: libwps_internal.h:401
WPSCellFormat::CompareFormat
a comparaison structure used to store data
Definition: WPSCell.h:248
WPSCellFormat::hasBasicFormat
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: WPSCell.h:87
WPSCellFormat::vAlignment
VerticalAlignment vAlignment() const
returns the vertical alignement
Definition: WPSCell.h:120
WPSCellFormat::borders
std::vector< WPSBorder > const & borders() const
return the cell border: libwps::LeftBit | ...
Definition: WPSCell.h:210
WPSCellFormat::hAlignment
HorizontalAlignment hAlignment() const
returns the horizontal alignement
Definition: WPSCell.h:109
WPSCellFormat::F_UNKNOWN
@ F_UNKNOWN
Definition: WPSCell.h:54
WPSCell::Compare::Point
small structure to define a cell point
Definition: WPSCell.h:373
WPSBorder::Right
@ Right
Definition: libwps_internal.h:400
WPSCell::Compare::operator()
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: WPSCell.h:392
WPSCell::Compare::Compare
Compare(int dim)
Definition: WPSCell.h:369
WPSCellFormat::setTextRotation
void setTextRotation(int rotation)
sets the text rotation angle
Definition: WPSCell.h:146
WPSCellFormat::wrapping
Wrapping wrapping() const
returns the wrapping
Definition: WPSCell.h:130
WPSColor::isWhite
bool isWhite() const
return true if the color is white
Definition: libwps_internal.h:350
WPSCellFormat::setFormat
void setFormat(FormatType form, int subForm=0)
sets the format type
Definition: WPSCell.h:167
WPSCellFormat::HALIGN_RIGHT
@ HALIGN_RIGHT
Definition: WPSCell.h:46
WPSFont
define the font properties
Definition: WPSFont.h:37
WPSCellFormat::m_digits
int m_digits
the number of digits
Definition: WPSCell.h:280
WPSCell::setPosition
void setPosition(Vec2i posi)
set the cell positions : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:340
WPSCellFormat::setWrapping
void setWrapping(Wrapping align)
sets the wrapping
Definition: WPSCell.h:135
WPSCellFormat::m_bordersList
std::vector< WPSBorder > m_bordersList
the cell border WPSBorder::Pos
Definition: WPSCell.h:272
WPSCell::numSpannedCells
Vec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: WPSCell.h:346
WPSListenerPtr
std::shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:105
WPSCellFormat::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:163
WPSTable
Definition: WPSTable.h:157
WPSBorder::Left
@ Left
Definition: libwps_internal.h:400
Vec2< int >
WPSBorder::TopBit
@ TopBit
Definition: libwps_internal.h:401
WPSCellFormat::m_format
FormatType m_format
the cell format : by default unknown
Definition: WPSCell.h:274
WPS_DEBUG_MSG
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:134
WPSCell::Compare::m_coord
int m_coord
the coord to compare
Definition: WPSCell.h:412
WPSCellFormat::getDTFormat
std::string getDTFormat() const
returns the date/time format ( if set)
Definition: WPSCell.h:162
WPSCellFormat::F_TIME
@ F_TIME
Definition: WPSCell.h:54
WPS_FALLTHROUGH
#define WPS_FALLTHROUGH
fall through attributes
Definition: libwps_internal.h:82
WPSCellFormat::F_NUMBER
@ F_NUMBER
Definition: WPSCell.h:54
WPSCellFormat::WRAP_NO_WRAP
@ WRAP_NO_WRAP
Definition: WPSCell.h:52
WPSCell::send
virtual bool send(WPSListenerPtr &listener)=0
call when a cell must be send
WPSCellFormat::setDTFormat
void setDTFormat(FormatType form, std::string const &dtFormat="")
sets the format type
Definition: WPSCell.h:173
WPSBorder::Bottom
@ Bottom
Definition: libwps_internal.h:400
WPSCellFormat::VALIGN_BOTTOM
@ VALIGN_BOTTOM
Definition: WPSCell.h:50
WPSCellFormat::digits
int digits() const
returns the number of digits ( for a number)
Definition: WPSCell.h:181
WPSFont.h
WPSCellFormat::F_TEXT
@ F_TEXT
Definition: WPSCell.h:54
WPSCellFormat::m_font
WPSFont m_font
the cell font ( used in spreadsheet code )
Definition: WPSCell.h:262
WPSCell::setVerticalSet
void setVerticalSet(bool verticalSet)
fixes or not the vertical size
Definition: WPSCell.h:325
WPSBorder::RightBit
@ RightBit
Definition: libwps_internal.h:401
WPSCellFormat::m_backgroundColor
WPSColor m_backgroundColor
the backgroung color
Definition: WPSCell.h:284
WPSCell::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:534
WPSCell::Compare::Point::getSize
float getSize(int coord) const
Definition: WPSCell.h:383
WPSCell::m_position
Vec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:420
WPSCellFormat
a structure used to defined the cell format
Definition: WPSCell.h:41
WPSBorder::m_style
Style m_style
the border style
Definition: libwps_internal.h:446
WPSCell::m_numberCellSpanned
Vec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: WPSCell.h:422
WPSCellFormat::HALIGN_LEFT
@ HALIGN_LEFT
Definition: WPSCell.h:46
WPSCellFormat::CompareFormat::CompareFormat
CompareFormat()
constructor
Definition: WPSCell.h:250
WPSCellFormat::VALIGN_TOP
@ VALIGN_TOP
Definition: WPSCell.h:50
WPSCellFormat::setHAlignment
void setHAlignment(HorizontalAlignment align)
sets the horizontal alignement
Definition: WPSCell.h:114
WPSCellFormat::VerticalAlignment
VerticalAlignment
the default vertical alignement.
Definition: WPSCell.h:50
WPSBox2::min
Vec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:725
WPSCellFormat::m_rotation
int m_rotation
the text rotation
Definition: WPSCell.h:270
WPSCellFormat::isProtected
bool isProtected() const
returns true if the cell is protected
Definition: WPSCell.h:192
WPSCell
a structure used to defined the cell position, and a format
Definition: WPSCell.h:291
WPSCellFormat::HorizontalAlignment
HorizontalAlignment
the default horizontal alignement.
Definition: WPSCell.h:46
WPSBorder
a border list
Definition: libwps_internal.h:395
WPSCell::sendContent
virtual bool sendContent(WPSListenerPtr &listener)=0
call when the content of a cell must be send
WPSCellFormat::hasBorders
bool hasBorders() const
return true if the cell has some border
Definition: WPSCell.h:204
WPSCellFormat::setProtected
void setProtected(bool fl)
returns true if the cell is protected
Definition: WPSCell.h:198
WPSCell::Compare::Point::getPos
float getPos(int coord) const
Definition: WPSCell.h:377
WPSCellFormat::getNumberingProperties
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the number style
Definition: WPSCell.cpp:281
WPSCellFormat::setFont
void setFont(WPSFont const &font)
sets the font
Definition: WPSCell.h:104
WPSCell::m_verticalSet
bool m_verticalSet
true if y size is fixed
Definition: WPSCell.h:418
WPSCellFormat::getValueType
std::string getValueType() const
returns a value type
Definition: WPSCell.cpp:246
WPSCell::operator=
WPSCell & operator=(WPSCell const &)=default
WPSCell::Compare
a comparaison structure used retrieve the rows and the columns
Definition: WPSCell.h:368
operator<<
std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
Definition: WPSCell.cpp:398
WPSCell::isVerticalSet
bool isVerticalSet() const
returns true if the vertical is fixed
Definition: WPSCell.h:320
WPSCell::position
Vec2i & position()
position accessor
Definition: WPSCell.h:330
WPSBox2::max
Vec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:730
WPSCell::m_box
WPSBox2f m_box
the cell bounding box (unit in point)
Definition: WPSCell.h:416
WPSBorder::LeftBit
@ LeftBit
Definition: libwps_internal.h:401
WPSCell::Compare::Point::m_which
int m_which
Definition: WPSCell.h:387
WPSBox2::size
Vec2< T > size() const
the box size
Definition: libwps_internal.h:754
WPSCellFormat::setDigits
void setDigits(int newDigit)
set the number of digits ( for a number)
Definition: WPSCell.h:186
WPSCell::box
WPSBox2f const & box() const
return the bounding box
Definition: WPSCell.h:315
WPSBorder::None
@ None
Definition: libwps_internal.h:397
WPSCellFormat::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
operator<<
Definition: WPSCell.cpp:398
libwps_internal.h
WPSCellFormat::F_DATE
@ F_DATE
Definition: WPSCell.h:54
WPSColor
the class to store a color
Definition: libwps_internal.h:281
WPSCellFormat::setBorders
void setBorders(std::vector< WPSBorder > const &newBorders)
sets the cell borders
Definition: WPSCell.h:224
WPSBox2< float >
WPSCellFormat::WPSCellFormat
WPSCellFormat()
constructor
Definition: WPSCell.h:69
WPSCell::Compare::Point::Point
Point(int wh, WPSCell const *cell)
Definition: WPSCell.h:374
WPSCellFormat::m_vAlign
VerticalAlignment m_vAlign
the cell vertical alignement : by default nothing
Definition: WPSCell.h:266
WPSCellFormat::m_protected
bool m_protected
cell protected
Definition: WPSCell.h:282
WPSCellFormat::setBorders
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=WPSBorder::LeftBit|...
Definition: WPSCell.cpp:143
WPSCellFormat::~WPSCellFormat
virtual ~WPSCellFormat()
destructor
Definition: WPSCell.cpp:35
WPSCell::setBox
void setBox(WPSBox2f const &b)
set the bounding box (units in point)
Definition: WPSCell.h:310
WPSCellFormat::Wrapping
Wrapping
the wrapping
Definition: WPSCell.h:52
WPSCellFormat::getTextRotation
int getTextRotation() const
returns the text rotation angle
Definition: WPSCell.h:141
WPSCellFormat::compare
int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const
a comparison function
Definition: WPSCell.cpp:366
WPSCellFormat::setBackgroundColor
void setBackgroundColor(WPSColor const &color)
set the background color
Definition: WPSCell.h:235
WPSCellFormat::WPSCellFormat
WPSCellFormat(WPSCellFormat const &)=default
WPSCellFormat::backgroundColor
WPSColor backgroundColor() const
returns the background color
Definition: WPSCell.h:230
WPSCellFormat::getFont
WPSFont const & getFont() const
returns the font
Definition: WPSCell.h:99
WPSCellFormat::m_hAlign
HorizontalAlignment m_hAlign
the cell alignement : by default nothing
Definition: WPSCell.h:264
WPSCellFormat::m_DTFormat
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: WPSCell.h:278
WPSCellFormat::resetBorders
void resetBorders()
reset the border
Definition: WPSCell.h:216
WPSCellFormat::getSubFormat
int getSubFormat() const
returns the subformat type
Definition: WPSCell.h:157
WPSCell::position
Vec2i const & position() const
position accessor
Definition: WPSCell.h:335
WPSCellFormat::HALIGN_CENTER
@ HALIGN_CENTER
Definition: WPSCell.h:46
WPSCell::setNumSpannedCells
void setNumSpannedCells(Vec2i numSpanned)
sets the number of spanned cells : Vec2i(1,1) means 1 cellule
Definition: WPSCell.h:351

Generated on Sat Sep 5 2020 04:52:14 for libwps by doxygen 1.8.19