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  };
51 
54 
55  /* subformat:
56  NUMBER DATE TIME TEXT
57  0 : default default[3/2/2000] default[10:03:00] default
58  1 : decimal
59  2 : exponential
60  3 : percent
61  4 : money
62  5 : thousand
63  6 : fixed
64  7 : fraction
65  */
66 
71  virtual ~WPSCellFormat() {}
73  bool hasBasicFormat() const
74  {
75  return m_format==F_TEXT || m_format==F_UNKNOWN;
76  }
78  std::string getValueType() const;
80  void addTo(librevenge::RVNGPropertyList &propList) const;
82  bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const;
83 
85  WPSFont const &getFont() const
86  {
87  return m_font;
88  }
90  void setFont(WPSFont const &font)
91  {
92  m_font=font;
93  }
96  {
97  return m_hAlign;
98  }
101  {
102  m_hAlign = align;
103  }
104 
107  {
108  return m_vAlign;
109  }
112  {
113  m_vAlign = align;
114  }
115 
118  {
119  return m_format;
120  }
122  int getSubFormat() const
123  {
124  return m_subFormat;
125  }
127  std::string getDTFormat() const
128  {
129  return m_DTFormat;
130  }
132  void setFormat(FormatType form, int subForm=0)
133  {
134  m_format = form;
135  m_subFormat = subForm;
136  }
138  void setDTFormat(FormatType form, std::string const &dtFormat="")
139  {
140  m_format = form;
141  m_subFormat = 0;
142  m_DTFormat = dtFormat;
143  }
144 
146  int digits() const
147  {
148  return m_digits;
149  }
151  void setDigits(int newDigit)
152  {
153  m_digits = newDigit;
154  }
155 
157  bool isProtected() const
158  {
159  return m_protected;
160  }
161 
163  void setProtected(bool fl)
164  {
165  m_protected = fl;
166  }
167 
169  bool hasBorders() const
170  {
171  return m_bordersList.size() != 0;
172  }
173 
175  std::vector<WPSBorder> const &borders() const
176  {
177  return m_bordersList;
178  }
179 
182  {
183  m_bordersList.resize(0);
184  }
185 
187  void setBorders(int wh, WPSBorder const &border);
188 
190  uint32_t backgroundColor() const
191  {
192  return m_backgroundColor;
193  }
195  void setBackgroundColor(uint32_t color)
196  {
197  m_backgroundColor = color;
198  }
199 
201  int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const;
202 
204  friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
205 
208  {
212  bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
213  {
214  return c1.compare(c2, true) < 0;
215  }
216  };
217 
218 protected:
220  static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
228  std::vector<WPSBorder> m_bordersList;
234  std::string m_DTFormat;
236  int m_digits;
241 };
242 
243 class WPSTable;
244 
246 class WPSCell : public WPSCellFormat
247 {
248  friend class WPSTable;
249 public:
253  virtual ~WPSCell() {}
254 
256  void addTo(librevenge::RVNGPropertyList &propList) const;
257 
259  void setBox(Box2f const &b)
260  {
261  m_box = b;
262  }
264  Box2f const &box() const
265  {
266  return m_box;
267  }
269  bool isVerticalSet() const
270  {
271  return m_verticalSet;
272  }
274  void setVerticalSet(bool verticalSet)
275  {
276  m_verticalSet = verticalSet;
277  }
280  {
281  return m_position;
282  }
284  Vec2i const &position() const
285  {
286  return m_position;
287  }
289  void setPosition(Vec2i posi)
290  {
291  m_position = posi;
292  }
293 
295  Vec2i const &numSpannedCells() const
296  {
297  return m_numberCellSpanned;
298  }
300  void setNumSpannedCells(Vec2i numSpanned)
301  {
302  m_numberCellSpanned=numSpanned;
303  }
304 
306  virtual bool send(WPSListenerPtr &listener) = 0;
307 
309  virtual bool sendContent(WPSListenerPtr &listener) = 0;
310 
312  friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
313 
314 protected:
316  struct Compare
317  {
318  Compare(int dim) : m_coord(dim) {}
320  struct Point
321  {
322  Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
323  float getPos(int coord) const
324  {
325  if (m_which)
326  return m_cell->box().max()[coord];
327  return m_cell->box().min()[coord];
328  }
329  float getSize(int coord) const
330  {
331  return m_cell->box().size()[coord];
332  }
333  int m_which;
334  WPSCell const *m_cell;
335  };
336 
338  bool operator()(Point const &c1, Point const &c2) const
339  {
340  float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
341  if (diffF < 0) return true;
342  if (diffF > 0) return false;
343  int diff = c2.m_which - c1.m_which;
344  if (diff) return (diff < 0);
345  diffF = c1.m_cell->box().size()[m_coord]
346  - c2.m_cell->box().size()[m_coord];
347  if (diffF < 0) return true;
348  if (diffF > 0) return false;
349  if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
350 #ifdef _WIN64
351  return ((__int64)c1.m_cell < (__int64)c2.m_cell);
352 #else
353  return long(c1.m_cell) < long(c2.m_cell);
354 #endif
355  }
356 
358  int m_coord;
359  };
360 
369 };
370 
371 #endif
372 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:493
Definition: WPSCell.h:53
int m_digits
the number of digits
Definition: WPSCell.h:236
void setBox(Box2f const &b)
set the bounding box (units in point)
Definition: WPSCell.h:259
friend std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
operator<<
Definition: WPSCell.cpp:372
a border list
Definition: libwps_internal.h:216
a comparaison structure used retrieve the rows and the columns
Definition: WPSCell.h:316
Point(int wh, WPSCell const *cell)
Definition: WPSCell.h:322
Vec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:504
Vec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: WPSCell.h:368
void setDigits(int newDigit)
set the number of digits ( for a number)
Definition: WPSCell.h:151
virtual ~WPSCell()
destructor
Definition: WPSCell.h:253
VerticalAlignment m_vAlign
the cell vertical alignement : by default nothing
Definition: WPSCell.h:226
Definition: WPSCell.h:50
void setFormat(FormatType form, int subForm=0)
sets the format type
Definition: WPSCell.h:132
Definition: WPSCell.h:53
define the font properties
Definition: WPSFont.h:37
Definition: WPSCell.h:50
bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
comparaison function
Definition: WPSCell.h:212
bool hasBorders() const
return true if the cell has some border
Definition: WPSCell.h:169
FormatType m_format
the cell format : by default unknown
Definition: WPSCell.h:230
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=WPSBorder::LeftBit|...
Definition: WPSCell.cpp:134
WPSCell()
constructor
Definition: WPSCell.h:251
void setVerticalSet(bool verticalSet)
fixes or not the vertical size
Definition: WPSCell.h:274
float getSize(int coord) const
Definition: WPSCell.h:329
Definition: WPSCell.h:50
HorizontalAlignment m_hAlign
the cell alignement : by default nothing
Definition: WPSCell.h:224
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: WPSCell.h:234
Definition: WPSCell.h:46
Definition: WPSCell.h:53
a structure used to defined the cell format
Definition: WPSCell.h:40
void setDTFormat(FormatType form, std::string const &dtFormat="")
sets the format type
Definition: WPSCell.h:138
void setVAlignement(VerticalAlignment align)
sets the vertical alignement
Definition: WPSCell.h:111
void setFont(WPSFont const &font)
sets the font
Definition: WPSCell.h:90
uint32_t backgroundColor() const
returns the background color
Definition: WPSCell.h:190
Definition: WPSCell.h:53
uint32_t m_backgroundColor
the backgroung color
Definition: WPSCell.h:240
Vec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: WPSCell.h:295
a structure used to defined the cell position, and a format
Definition: WPSCell.h:246
void setNumSpannedCells(Vec2i numSpanned)
sets the number of spanned cells : Vec2i(1,1) means 1 cellule
Definition: WPSCell.h:300
FormatType
the different types of cell's field
Definition: WPSCell.h:53
a comparaison structure used to store data
Definition: WPSCell.h:207
bool isVerticalSet() const
returns true if the vertical is fixed
Definition: WPSCell.h:269
WPSFont const & getFont() const
returns the font
Definition: WPSCell.h:85
void setProtected(bool fl)
returns true if the cell is protected
Definition: WPSCell.h:163
HorizontalAlignment hAlignement() const
returns the horizontal alignement
Definition: WPSCell.h:95
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:154
std::vector< WPSBorder > m_bordersList
the cell border WPSBorder::Pos
Definition: WPSCell.h:228
shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:98
Definition: WPSCell.h:50
FormatType getFormat() const
returns the format type
Definition: WPSCell.h:117
Definition: WPSCell.h:53
VerticalAlignment vAlignement() const
returns the vertical alignement
Definition: WPSCell.h:106
Box2f m_box
the cell bounding box (unit in point)
Definition: WPSCell.h:362
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the number style
Definition: WPSCell.cpp:261
Definition: WPSCell.h:53
std::string getDTFormat() const
returns the date/time format ( if set)
Definition: WPSCell.h:127
int m_coord
the coord to compare
Definition: WPSCell.h:358
int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const
a comparison function
Definition: WPSCell.cpp:344
Vec2i const & position() const
position accessor
Definition: WPSCell.h:284
Vec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:509
int m_subFormat
the sub format
Definition: WPSCell.h:232
Compare(int dim)
Definition: WPSCell.h:318
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: WPSCell.h:338
small structure to define a cell point
Definition: WPSCell.h:320
float getPos(int coord) const
Definition: WPSCell.h:323
virtual bool sendContent(WPSListenerPtr &listener)=0
call when the content of a cell must be send
void setBackgroundColor(uint32_t color)
set the background color
Definition: WPSCell.h:195
static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector)
convert a DTFormat in a propertyList
Definition: WPSCell.cpp:35
void resetBorders()
reset the border
Definition: WPSCell.h:181
Definition: WPSCell.h:47
Box2f const & box() const
return the bounding box
Definition: WPSCell.h:264
void setPosition(Vec2i posi)
set the cell positions : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:289
std::string getValueType() const
returns a value type
Definition: WPSCell.cpp:226
int getSubFormat() const
returns the subformat type
Definition: WPSCell.h:122
int digits() const
returns the number of digits ( for a number)
Definition: WPSCell.h:146
Vec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:366
WPSCell const * m_cell
Definition: WPSCell.h:334
bool m_protected
cell protected
Definition: WPSCell.h:238
void setHAlignement(HorizontalAlignment align)
sets the horizontal alignement
Definition: WPSCell.h:100
virtual bool send(WPSListenerPtr &listener)=0
call when a cell must be send
Definition: WPSCell.h:46
Definition: WPSCell.h:47
int m_which
Definition: WPSCell.h:333
std::vector< WPSBorder > const & borders() const
return the cell border: libwps::LeftBit | ...
Definition: WPSCell.h:175
WPSFont m_font
the cell font ( used in spreadsheet code )
Definition: WPSCell.h:222
virtual ~WPSCellFormat()
destructor
Definition: WPSCell.h:71
Definition: WPSTable.h:39
bool m_verticalSet
true if y size is fixed
Definition: WPSCell.h:364
Vec2< T > size() const
the box size
Definition: libwps_internal.h:534
friend std::ostream & operator<<(std::ostream &o, WPSCell const &cell)
operator<<
Definition: WPSCell.cpp:504
Definition: WPSCell.h:46
HorizontalAlignment
the default horizontal alignement.
Definition: WPSCell.h:46
VerticalAlignment
the default vertical alignement.
Definition: WPSCell.h:50
CompareFormat()
constructor
Definition: WPSCell.h:210
Vec2i & position()
position accessor
Definition: WPSCell.h:279
bool isProtected() const
returns true if the cell is protected
Definition: WPSCell.h:157
WPSCellFormat()
constructor
Definition: WPSCell.h:68
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: WPSCell.h:73

Generated on Thu Oct 9 2014 14:30:03 for libwps by doxygen 1.8.8