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()) { }
83  virtual ~WPSCellFormat() {}
85  bool hasBasicFormat() const
86  {
87  return m_format==F_TEXT || m_format==F_UNKNOWN;
88  }
90  std::string getValueType() const;
92  void addTo(librevenge::RVNGPropertyList &propList) const;
94  bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const;
95 
97  WPSFont const &getFont() const
98  {
99  return m_font;
100  }
102  void setFont(WPSFont const &font)
103  {
104  m_font=font;
105  }
108  {
109  return m_hAlign;
110  }
113  {
114  m_hAlign = align;
115  }
116 
119  {
120  return m_vAlign;
121  }
124  {
125  m_vAlign = align;
126  }
129  {
130  return m_wrapping;
131  }
133  void setWrapping(Wrapping align)
134  {
135  m_wrapping = align;
136  }
137 
139  int getTextRotation() const
140  {
141  return m_rotation;
142  }
144  void setTextRotation(int rotation)
145  {
146  m_rotation = rotation;
147  }
148 
151  {
152  return m_format;
153  }
155  int getSubFormat() const
156  {
157  return m_subFormat;
158  }
160  std::string getDTFormat() const
161  {
162  return m_DTFormat;
163  }
165  void setFormat(FormatType form, int subForm=0)
166  {
167  m_format = form;
168  m_subFormat = subForm;
169  }
171  void setDTFormat(FormatType form, std::string const &dtFormat="")
172  {
173  m_format = form;
174  m_subFormat = 0;
175  m_DTFormat = dtFormat;
176  }
177 
179  int digits() const
180  {
181  return m_digits;
182  }
184  void setDigits(int newDigit)
185  {
186  m_digits = newDigit;
187  }
188 
190  bool isProtected() const
191  {
192  return m_protected;
193  }
194 
196  void setProtected(bool fl)
197  {
198  m_protected = fl;
199  }
200 
202  bool hasBorders() const
203  {
204  return m_bordersList.size() != 0;
205  }
206 
208  std::vector<WPSBorder> const &borders() const
209  {
210  return m_bordersList;
211  }
212 
215  {
216  m_bordersList.resize(0);
217  }
218 
220  void setBorders(int wh, WPSBorder const &border);
222  void setBorders(std::vector<WPSBorder> const &newBorders)
223  {
224  m_bordersList=newBorders;
225  }
226 
229  {
230  return m_backgroundColor;
231  }
233  void setBackgroundColor(WPSColor const &color)
234  {
235  m_backgroundColor = color;
236  }
237 
239  int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const;
240 
242  friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
243 
246  {
250  bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
251  {
252  return c1.compare(c2, true) < 0;
253  }
254  };
255 
256 protected:
258  static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
270  std::vector<WPSBorder> m_bordersList;
276  std::string m_DTFormat;
278  int m_digits;
283 };
284 
285 class WPSTable;
286 
288 class WPSCell : public WPSCellFormat
289 {
290  friend class WPSTable;
291 public:
294  : WPSCellFormat()
295  , m_box()
296  , m_verticalSet(true)
297  , m_position(0,0)
298  , m_numberCellSpanned(1,1) {}
300  ~WPSCell() override {}
301 
303  void addTo(librevenge::RVNGPropertyList &propList) const;
304 
306  void setBox(WPSBox2f const &b)
307  {
308  m_box = b;
309  }
311  WPSBox2f const &box() const
312  {
313  return m_box;
314  }
316  bool isVerticalSet() const
317  {
318  return m_verticalSet;
319  }
321  void setVerticalSet(bool verticalSet)
322  {
323  m_verticalSet = verticalSet;
324  }
327  {
328  return m_position;
329  }
331  Vec2i const &position() const
332  {
333  return m_position;
334  }
336  void setPosition(Vec2i posi)
337  {
338  m_position = posi;
339  }
340 
342  Vec2i const &numSpannedCells() const
343  {
344  return m_numberCellSpanned;
345  }
347  void setNumSpannedCells(Vec2i numSpanned)
348  {
349  m_numberCellSpanned=numSpanned;
350  }
351 
353  virtual bool send(WPSListenerPtr &listener) = 0;
354 
356  virtual bool sendContent(WPSListenerPtr &listener) = 0;
357 
359  friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
360 
361 protected:
363  struct Compare
364  {
365  explicit Compare(int dim)
366  : m_coord(dim) {}
368  struct Point
369  {
370  Point(int wh, WPSCell const *cell)
371  : m_which(wh)
372  , m_cell(cell) {}
373  float getPos(int coord) const
374  {
375  if (m_which)
376  return m_cell->box().max()[coord];
377  return m_cell->box().min()[coord];
378  }
379  float getSize(int coord) const
380  {
381  return m_cell->box().size()[coord];
382  }
383  int m_which;
384  WPSCell const *m_cell;
385  };
386 
388  bool operator()(Point const &c1, Point const &c2) const
389  {
390  float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
391  if (diffF < 0) return true;
392  if (diffF > 0) return false;
393  int diff = c2.m_which - c1.m_which;
394  if (diff) return (diff < 0);
395  diffF = c1.m_cell->box().size()[m_coord]
396  - c2.m_cell->box().size()[m_coord];
397  if (diffF < 0) return true;
398  if (diffF > 0) return false;
399  if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
400 #ifdef _WIN64
401  return ((__int64)c1.m_cell < (__int64)c2.m_cell);
402 #else
403  return long(c1.m_cell) < long(c2.m_cell);
404 #endif
405  }
406 
408  int m_coord;
409  };
410 
419 };
420 
421 #endif
422 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Definition: WPSCell.h:54
bool hasBorders() const
return true if the cell has some border
Definition: WPSCell.h:202
int m_digits
the number of digits
Definition: WPSCell.h:278
std::shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:105
friend std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
operator<<
Definition: WPSCell.cpp:394
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:159
a border list
Definition: libwps_internal.h:394
a comparaison structure used retrieve the rows and the columns
Definition: WPSCell.h:363
WPSColor backgroundColor() const
returns the background color
Definition: WPSCell.h:228
Vec2< T > size() const
the box size
Definition: libwps_internal.h:754
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: WPSCell.h:388
Point(int wh, WPSCell const *cell)
Definition: WPSCell.h:370
Vec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: WPSCell.h:418
void setDigits(int newDigit)
set the number of digits ( for a number)
Definition: WPSCell.h:184
WPSBox2f const & box() const
return the bounding box
Definition: WPSCell.h:311
Wrapping m_wrapping
the wrapping : by default nothing
Definition: WPSCell.h:266
VerticalAlignment m_vAlign
the cell vertical alignement : by default nothing
Definition: WPSCell.h:264
Definition: WPSCell.h:50
void setFormat(FormatType form, int subForm=0)
sets the format type
Definition: WPSCell.h:165
Definition: WPSCell.h:54
define the font properties
Definition: WPSFont.h:36
Definition: WPSCell.h:50
VerticalAlignment vAlignment() const
returns the vertical alignement
Definition: WPSCell.h:118
FormatType m_format
the cell format : by default unknown
Definition: WPSCell.h:272
void setBox(WPSBox2f const &b)
set the bounding box (units in point)
Definition: WPSCell.h:306
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=WPSBorder::LeftBit|...
Definition: WPSCell.cpp:139
int m_rotation
the text rotation
Definition: WPSCell.h:268
WPSCell()
constructor
Definition: WPSCell.h:293
void setVerticalSet(bool verticalSet)
fixes or not the vertical size
Definition: WPSCell.h:321
Vec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:730
Definition: WPSCell.h:50
HorizontalAlignment m_hAlign
the cell alignement : by default nothing
Definition: WPSCell.h:262
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: WPSCell.h:276
Definition: WPSCell.h:46
Definition: WPSCell.h:54
a structure used to defined the cell format
Definition: WPSCell.h:40
Definition: WPSCell.h:52
void setDTFormat(FormatType form, std::string const &dtFormat="")
sets the format type
Definition: WPSCell.h:171
void setFont(WPSFont const &font)
sets the font
Definition: WPSCell.h:102
std::vector< WPSBorder > const & borders() const
return the cell border: libwps::LeftBit | ...
Definition: WPSCell.h:208
Definition: WPSCell.h:54
a structure used to defined the cell position, and a format
Definition: WPSCell.h:288
Definition: WPSCell.h:52
void setNumSpannedCells(Vec2i numSpanned)
sets the number of spanned cells : Vec2i(1,1) means 1 cellule
Definition: WPSCell.h:347
FormatType
the different types of cell&#39;s field
Definition: WPSCell.h:54
a comparaison structure used to store data
Definition: WPSCell.h:245
void setProtected(bool fl)
returns true if the cell is protected
Definition: WPSCell.h:196
Wrapping wrapping() const
returns the wrapping
Definition: WPSCell.h:128
Wrapping
the wrapping
Definition: WPSCell.h:52
std::string getDTFormat() const
returns the date/time format ( if set)
Definition: WPSCell.h:160
std::vector< WPSBorder > m_bordersList
the cell border WPSBorder::Pos
Definition: WPSCell.h:270
void setBackgroundColor(WPSColor const &color)
set the background color
Definition: WPSCell.h:233
Definition: WPSCell.h:50
void setWrapping(Wrapping align)
sets the wrapping
Definition: WPSCell.h:133
Definition: WPSCell.h:54
Definition: WPSCell.h:54
bool isVerticalSet() const
returns true if the vertical is fixed
Definition: WPSCell.h:316
int m_coord
the coord to compare
Definition: WPSCell.h:408
HorizontalAlignment hAlignment() const
returns the horizontal alignement
Definition: WPSCell.h:107
int m_subFormat
the sub format
Definition: WPSCell.h:274
Compare(int dim)
Definition: WPSCell.h:365
~WPSCell() override
destructor
Definition: WPSCell.h:300
float getPos(int coord) const
Definition: WPSCell.h:373
float getSize(int coord) const
Definition: WPSCell.h:379
small structure to define a cell point
Definition: WPSCell.h:368
int getTextRotation() const
returns the text rotation angle
Definition: WPSCell.h:139
virtual bool sendContent(WPSListenerPtr &listener)=0
call when the content of a cell must be send
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:214
Definition: WPSCell.h:47
void setPosition(Vec2i posi)
set the cell positions : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:336
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: WPSCell.h:85
the class to store a color
Definition: libwps_internal.h:280
bool isProtected() const
returns true if the cell is protected
Definition: WPSCell.h:190
bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
comparaison function
Definition: WPSCell.h:250
Vec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:416
WPSCell const * m_cell
Definition: WPSCell.h:384
bool m_protected
cell protected
Definition: WPSCell.h:280
FormatType getFormat() const
returns the format type
Definition: WPSCell.h:150
int digits() const
returns the number of digits ( for a number)
Definition: WPSCell.h:179
std::string getValueType() const
returns a value type
Definition: WPSCell.cpp:242
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:383
WPSFont m_font
the cell font ( used in spreadsheet code )
Definition: WPSCell.h:260
Vec2i const & position() const
position accessor
Definition: WPSCell.h:331
WPSColor m_backgroundColor
the backgroung color
Definition: WPSCell.h:282
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the number style
Definition: WPSCell.cpp:277
virtual ~WPSCellFormat()
destructor
Definition: WPSCell.h:83
Definition: WPSTable.h:156
void setHAlignment(HorizontalAlignment align)
sets the horizontal alignement
Definition: WPSCell.h:112
Vec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: WPSCell.h:342
bool m_verticalSet
true if y size is fixed
Definition: WPSCell.h:414
friend std::ostream & operator<<(std::ostream &o, WPSCell const &cell)
operator<<
Definition: WPSCell.cpp:536
void setVAlignment(VerticalAlignment align)
sets the vertical alignement
Definition: WPSCell.h:123
WPSBox2f m_box
the cell bounding box (unit in point)
Definition: WPSCell.h:412
void setTextRotation(int rotation)
sets the text rotation angle
Definition: WPSCell.h:144
Definition: WPSCell.h:46
Vec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:725
HorizontalAlignment
the default horizontal alignement.
Definition: WPSCell.h:46
int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const
a comparison function
Definition: WPSCell.cpp:362
void setBorders(std::vector< WPSBorder > const &newBorders)
sets the cell borders
Definition: WPSCell.h:222
VerticalAlignment
the default vertical alignement.
Definition: WPSCell.h:50
WPSFont const & getFont() const
returns the font
Definition: WPSCell.h:97
CompareFormat()
constructor
Definition: WPSCell.h:248
Vec2i & position()
position accessor
Definition: WPSCell.h:326
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:525
WPSCellFormat()
constructor
Definition: WPSCell.h:69
Definition: WPSCell.h:52
int getSubFormat() const
returns the subformat type
Definition: WPSCell.h:155

Generated on Fri May 27 2022 03:07:00 for libwps by doxygen 1.8.14