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 
69  m_font(), m_hAlign(HALIGN_DEFAULT), m_vAlign(VALIGN_DEFAULT), m_rotation(0), m_bordersList(), m_format(F_UNKNOWN), m_subFormat(0), m_DTFormat(""), m_digits(-1000), m_protected(false), m_backgroundColor(WPSColor::white()) { }
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 
117  int getTextRotation() const
118  {
119  return m_rotation;
120  }
122  void setTextRotation(int rotation)
123  {
124  m_rotation = rotation;
125  }
126 
129  {
130  return m_format;
131  }
133  int getSubFormat() const
134  {
135  return m_subFormat;
136  }
138  std::string getDTFormat() const
139  {
140  return m_DTFormat;
141  }
143  void setFormat(FormatType form, int subForm=0)
144  {
145  m_format = form;
146  m_subFormat = subForm;
147  }
149  void setDTFormat(FormatType form, std::string const &dtFormat="")
150  {
151  m_format = form;
152  m_subFormat = 0;
153  m_DTFormat = dtFormat;
154  }
155 
157  int digits() const
158  {
159  return m_digits;
160  }
162  void setDigits(int newDigit)
163  {
164  m_digits = newDigit;
165  }
166 
168  bool isProtected() const
169  {
170  return m_protected;
171  }
172 
174  void setProtected(bool fl)
175  {
176  m_protected = fl;
177  }
178 
180  bool hasBorders() const
181  {
182  return m_bordersList.size() != 0;
183  }
184 
186  std::vector<WPSBorder> const &borders() const
187  {
188  return m_bordersList;
189  }
190 
193  {
194  m_bordersList.resize(0);
195  }
196 
198  void setBorders(int wh, WPSBorder const &border);
200  void setBorders(std::vector<WPSBorder> const &newBorders)
201  {
202  m_bordersList=newBorders;
203  }
204 
207  {
208  return m_backgroundColor;
209  }
211  void setBackgroundColor(WPSColor const &color)
212  {
213  m_backgroundColor = color;
214  }
215 
217  int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const;
218 
220  friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
221 
224  {
228  bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
229  {
230  return c1.compare(c2, true) < 0;
231  }
232  };
233 
234 protected:
236  static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
246  std::vector<WPSBorder> m_bordersList;
252  std::string m_DTFormat;
254  int m_digits;
259 };
260 
261 class WPSTable;
262 
264 class WPSCell : public WPSCellFormat
265 {
266  friend class WPSTable;
267 public:
269  WPSCell() : WPSCellFormat(), m_box(), m_verticalSet(true), m_position(0,0), m_numberCellSpanned(1,1) {}
271  virtual ~WPSCell() {}
272 
274  void addTo(librevenge::RVNGPropertyList &propList) const;
275 
277  void setBox(WPSBox2f const &b)
278  {
279  m_box = b;
280  }
282  WPSBox2f const &box() const
283  {
284  return m_box;
285  }
287  bool isVerticalSet() const
288  {
289  return m_verticalSet;
290  }
292  void setVerticalSet(bool verticalSet)
293  {
294  m_verticalSet = verticalSet;
295  }
298  {
299  return m_position;
300  }
302  Vec2i const &position() const
303  {
304  return m_position;
305  }
307  void setPosition(Vec2i posi)
308  {
309  m_position = posi;
310  }
311 
313  Vec2i const &numSpannedCells() const
314  {
315  return m_numberCellSpanned;
316  }
318  void setNumSpannedCells(Vec2i numSpanned)
319  {
320  m_numberCellSpanned=numSpanned;
321  }
322 
324  virtual bool send(WPSListenerPtr &listener) = 0;
325 
327  virtual bool sendContent(WPSListenerPtr &listener) = 0;
328 
330  friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
331 
332 protected:
334  struct Compare
335  {
336  explicit Compare(int dim) : m_coord(dim) {}
338  struct Point
339  {
340  Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
341  float getPos(int coord) const
342  {
343  if (m_which)
344  return m_cell->box().max()[coord];
345  return m_cell->box().min()[coord];
346  }
347  float getSize(int coord) const
348  {
349  return m_cell->box().size()[coord];
350  }
351  int m_which;
352  WPSCell const *m_cell;
353  };
354 
356  bool operator()(Point const &c1, Point const &c2) const
357  {
358  float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
359  if (diffF < 0) return true;
360  if (diffF > 0) return false;
361  int diff = c2.m_which - c1.m_which;
362  if (diff) return (diff < 0);
363  diffF = c1.m_cell->box().size()[m_coord]
364  - c2.m_cell->box().size()[m_coord];
365  if (diffF < 0) return true;
366  if (diffF > 0) return false;
367  if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
368 #ifdef _WIN64
369  return ((__int64)c1.m_cell < (__int64)c2.m_cell);
370 #else
371  return long(c1.m_cell) < long(c2.m_cell);
372 #endif
373  }
374 
376  int m_coord;
377  };
378 
387 };
388 
389 #endif
390 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Definition: WPSCell.h:53
bool hasBorders() const
return true if the cell has some border
Definition: WPSCell.h:180
int m_digits
the number of digits
Definition: WPSCell.h:254
friend std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
operator<<
Definition: WPSCell.cpp:375
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:156
a border list
Definition: libwps_internal.h:374
a comparaison structure used retrieve the rows and the columns
Definition: WPSCell.h:334
WPSColor backgroundColor() const
returns the background color
Definition: WPSCell.h:206
HorizontalAlignment hAlignement() const
returns the horizontal alignement
Definition: WPSCell.h:95
Vec2< T > size() const
the box size
Definition: libwps_internal.h:766
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: WPSCell.h:356
Point(int wh, WPSCell const *cell)
Definition: WPSCell.h:340
Vec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: WPSCell.h:386
void setDigits(int newDigit)
set the number of digits ( for a number)
Definition: WPSCell.h:162
WPSBox2f const & box() const
return the bounding box
Definition: WPSCell.h:282
virtual ~WPSCell()
destructor
Definition: WPSCell.h:271
VerticalAlignment m_vAlign
the cell vertical alignement : by default nothing
Definition: WPSCell.h:242
Definition: WPSCell.h:50
void setFormat(FormatType form, int subForm=0)
sets the format type
Definition: WPSCell.h:143
Definition: WPSCell.h:53
define the font properties
Definition: WPSFont.h:36
Definition: WPSCell.h:50
FormatType m_format
the cell format : by default unknown
Definition: WPSCell.h:248
void setBox(WPSBox2f const &b)
set the bounding box (units in point)
Definition: WPSCell.h:277
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=WPSBorder::LeftBit|...
Definition: WPSCell.cpp:136
int m_rotation
the text rotation
Definition: WPSCell.h:244
WPSCell()
constructor
Definition: WPSCell.h:269
void setVerticalSet(bool verticalSet)
fixes or not the vertical size
Definition: WPSCell.h:292
Definition: WPSCell.h:50
HorizontalAlignment m_hAlign
the cell alignement : by default nothing
Definition: WPSCell.h:240
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: WPSCell.h:252
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:149
void setVAlignement(VerticalAlignment align)
sets the vertical alignement
Definition: WPSCell.h:111
void setFont(WPSFont const &font)
sets the font
Definition: WPSCell.h:90
std::vector< WPSBorder > const & borders() const
return the cell border: libwps::LeftBit | ...
Definition: WPSCell.h:186
Definition: WPSCell.h:53
a structure used to defined the cell position, and a format
Definition: WPSCell.h:264
void setNumSpannedCells(Vec2i numSpanned)
sets the number of spanned cells : Vec2i(1,1) means 1 cellule
Definition: WPSCell.h:318
FormatType
the different types of cell&#39;s field
Definition: WPSCell.h:53
a comparaison structure used to store data
Definition: WPSCell.h:223
void setProtected(bool fl)
returns true if the cell is protected
Definition: WPSCell.h:174
std::string getDTFormat() const
returns the date/time format ( if set)
Definition: WPSCell.h:138
std::vector< WPSBorder > m_bordersList
the cell border WPSBorder::Pos
Definition: WPSCell.h:246
shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:106
void setBackgroundColor(WPSColor const &color)
set the background color
Definition: WPSCell.h:211
Definition: WPSCell.h:50
Definition: WPSCell.h:53
Definition: WPSCell.h:53
bool isVerticalSet() const
returns true if the vertical is fixed
Definition: WPSCell.h:287
int m_coord
the coord to compare
Definition: WPSCell.h:376
VerticalAlignment vAlignement() const
returns the vertical alignement
Definition: WPSCell.h:106
int m_subFormat
the sub format
Definition: WPSCell.h:250
Compare(int dim)
Definition: WPSCell.h:336
float getPos(int coord) const
Definition: WPSCell.h:341
float getSize(int coord) const
Definition: WPSCell.h:347
small structure to define a cell point
Definition: WPSCell.h:338
int getTextRotation() const
returns the text rotation angle
Definition: WPSCell.h:117
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:192
Definition: WPSCell.h:47
void setPosition(Vec2i posi)
set the cell positions : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:307
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: WPSCell.h:73
the class to store a color
Definition: libwps_internal.h:268
bool isProtected() const
returns true if the cell is protected
Definition: WPSCell.h:168
bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
comparaison function
Definition: WPSCell.h:228
Vec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:384
WPSCell const * m_cell
Definition: WPSCell.h:352
bool m_protected
cell protected
Definition: WPSCell.h:256
FormatType getFormat() const
returns the format type
Definition: WPSCell.h:128
int digits() const
returns the number of digits ( for a number)
Definition: WPSCell.h:157
void setHAlignement(HorizontalAlignment align)
sets the horizontal alignement
Definition: WPSCell.h:100
std::string getValueType() const
returns a value type
Definition: WPSCell.cpp:225
Definition: WPSCell.h:46
Definition: WPSCell.h:47
int m_which
Definition: WPSCell.h:351
WPSFont m_font
the cell font ( used in spreadsheet code )
Definition: WPSCell.h:238
Vec2i const & position() const
position accessor
Definition: WPSCell.h:302
WPSColor m_backgroundColor
the backgroung color
Definition: WPSCell.h:258
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the number style
Definition: WPSCell.cpp:260
virtual ~WPSCellFormat()
destructor
Definition: WPSCell.h:71
Definition: WPSTable.h:39
Vec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: WPSCell.h:313
bool m_verticalSet
true if y size is fixed
Definition: WPSCell.h:382
WPSBox2f m_box
the cell bounding box (unit in point)
Definition: WPSCell.h:380
void setTextRotation(int rotation)
sets the text rotation angle
Definition: WPSCell.h:122
Definition: WPSCell.h:46
HorizontalAlignment
the default horizontal alignement.
Definition: WPSCell.h:46
int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const
a comparison function
Definition: WPSCell.cpp:345
void setBorders(std::vector< WPSBorder > const &newBorders)
sets the cell borders
Definition: WPSCell.h:200
VerticalAlignment
the default vertical alignement.
Definition: WPSCell.h:50
WPSFont const & getFont() const
returns the font
Definition: WPSCell.h:85
CompareFormat()
constructor
Definition: WPSCell.h:226
Vec2i & position()
position accessor
Definition: WPSCell.h:297
WPSCellFormat()
constructor
Definition: WPSCell.h:68
int getSubFormat() const
returns the subformat type
Definition: WPSCell.h:133

Generated on Fri Jan 13 2017 20:06:02 for libwps by doxygen 1.8.12