WPSCell.h Source File documentation

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
40 class WPSCellFormat
41 {
42 public:
46 enum HorizontalAlignment { HALIGN_LEFT, HALIGN_RIGHT, HALIGN_CENTER,
47 HALIGN_FULL, HALIGN_DEFAULT
48 };
50 enum VerticalAlignment { VALIGN_TOP, VALIGN_CENTER, VALIGN_BOTTOM, VALIGN_DEFAULT };
52 enum Wrapping { WRAP_WRAP, WRAP_NO_WRAP, WRAP_DEFAULT };
54 enum FormatType { F_TEXT, F_BOOLEAN, F_NUMBER, F_DATE, F_TIME, F_UNKNOWN };
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
69 WPSCellFormat()
70 : m_font()
71 , m_hAlign(HALIGN_DEFAULT)
72 , m_vAlign(VALIGN_DEFAULT)
73 , m_wrapping(WRAP_DEFAULT)
74 , m_rotation(0)
75 , m_bordersList()
76 , m_format(F_UNKNOWN)
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 }
107 HorizontalAlignment hAlignement() const
108 {
109 return m_hAlign;
110 }
112 void setHAlignement(HorizontalAlignment align)
113 {
114 m_hAlign = align;
115 }
116
118 VerticalAlignment vAlignement() const
119 {
120 return m_vAlign;
121 }
123 void setVAlignement(VerticalAlignment align)
124 {
125 m_vAlign = align;
126 }
128 Wrapping wrapping() const
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
150 FormatType getFormat() const
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
214 void resetBorders()
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
228 WPSColor backgroundColor() const
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
245 struct CompareFormat
246 {
248 CompareFormat() {}
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);
260 WPSFont m_font;
262 HorizontalAlignment m_hAlign;
264 VerticalAlignment m_vAlign;
266 Wrapping m_wrapping;
268 int m_rotation;
270 std::vector<WPSBorder> m_bordersList;
272 FormatType m_format;
274 int m_subFormat;
276 std::string m_DTFormat;
278 int m_digits;
280 bool m_protected;
282 WPSColor m_backgroundColor;
283 };
284
285 class WPSTable;
286
288 class WPSCell : public WPSCellFormat
289 {
290 friend class WPSTable;
291 public:
293 WPSCell()
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 }
326 Vec2i &position()
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
412 WPSBox2f m_box;
414 bool m_verticalSet;
416 Vec2i m_position;
418 Vec2i m_numberCellSpanned;
419 };
420
421 #endif
422 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSCellFormat::F_TIME
Definition: WPSCell.h:54
WPSCellFormat::hasBorders
bool hasBorders() const
return true if the cell has some border
Definition: WPSCell.h:202
WPSCellFormat::m_digits
int m_digits
the number of digits
Definition: WPSCell.h:278
WPSListenerPtr
std::shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:105
WPSCellFormat::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
operator<<
Definition: WPSCell.cpp:394
WPSCellFormat::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:159
WPSBorder
a border list
Definition: libwps_internal.h:394
WPSCell::Compare
a comparaison structure used retrieve the rows and the columns
Definition: WPSCell.h:363
WPSCellFormat::backgroundColor
WPSColor backgroundColor() const
returns the background color
Definition: WPSCell.h:228
WPSCellFormat::hAlignement
HorizontalAlignment hAlignement() const
returns the horizontal alignement
Definition: WPSCell.h:107
WPSBox2::size
Vec2< T > size() const
the box size
Definition: libwps_internal.h:754
WPSCell::Compare::operator()
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: WPSCell.h:388
WPSCell::Compare::Point::Point
Point(int wh, WPSCell const *cell)
Definition: WPSCell.h:370
WPSCell::m_numberCellSpanned
Vec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: WPSCell.h:418
WPSCellFormat::setDigits
void setDigits(int newDigit)
set the number of digits ( for a number)
Definition: WPSCell.h:184
WPSCell::box
WPSBox2f const & box() const
return the bounding box
Definition: WPSCell.h:311
WPSCellFormat::m_wrapping
Wrapping m_wrapping
the wrapping : by default nothing
Definition: WPSCell.h:266
WPSCellFormat::m_vAlign
VerticalAlignment m_vAlign
the cell vertical alignement : by default nothing
Definition: WPSCell.h:264
WPSCellFormat::VALIGN_BOTTOM
Definition: WPSCell.h:50
WPSCellFormat::setFormat
void setFormat(FormatType form, int subForm=0)
sets the format type
Definition: WPSCell.h:165
WPSCellFormat::F_DATE
Definition: WPSCell.h:54
WPSFont
define the font properties
Definition: WPSFont.h:36
WPSCellFormat::VALIGN_DEFAULT
Definition: WPSCell.h:50
WPSCellFormat::m_format
FormatType m_format
the cell format : by default unknown
Definition: WPSCell.h:272
WPSCell::setBox
void setBox(WPSBox2f const &b)
set the bounding box (units in point)
Definition: WPSCell.h:306
WPSCellFormat::setBorders
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=WPSBorder::LeftBit|...
Definition: WPSCell.cpp:139
WPSCellFormat::m_rotation
int m_rotation
the text rotation
Definition: WPSCell.h:268
WPSCell::WPSCell
WPSCell()
constructor
Definition: WPSCell.h:293
WPSCell::setVerticalSet
void setVerticalSet(bool verticalSet)
fixes or not the vertical size
Definition: WPSCell.h:321
WPSBox2::max
Vec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:730
WPSCellFormat::VALIGN_CENTER
Definition: WPSCell.h:50
WPSCellFormat::m_hAlign
HorizontalAlignment m_hAlign
the cell alignement : by default nothing
Definition: WPSCell.h:262
WPSCellFormat::m_DTFormat
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: WPSCell.h:276
WPSCellFormat::HALIGN_LEFT
Definition: WPSCell.h:46
WPSCellFormat::F_TEXT
Definition: WPSCell.h:54
WPSCellFormat
a structure used to defined the cell format
Definition: WPSCell.h:40
WPSCellFormat::WRAP_WRAP
Definition: WPSCell.h:52
WPSCellFormat::setDTFormat
void setDTFormat(FormatType form, std::string const &dtFormat="")
sets the format type
Definition: WPSCell.h:171
WPSCellFormat::setVAlignement
void setVAlignement(VerticalAlignment align)
sets the vertical alignement
Definition: WPSCell.h:123
WPSCellFormat::setFont
void setFont(WPSFont const &font)
sets the font
Definition: WPSCell.h:102
WPSCellFormat::borders
std::vector< WPSBorder > const & borders() const
return the cell border: libwps::LeftBit | ...
Definition: WPSCell.h:208
WPSCellFormat::F_NUMBER
Definition: WPSCell.h:54
WPSCell
a structure used to defined the cell position, and a format
Definition: WPSCell.h:288
WPSCellFormat::WRAP_NO_WRAP
Definition: WPSCell.h:52
WPSCell::setNumSpannedCells
void setNumSpannedCells(Vec2i numSpanned)
sets the number of spanned cells : Vec2i(1,1) means 1 cellule
Definition: WPSCell.h:347
WPSCellFormat::FormatType
FormatType
the different types of cell&#39;s field
Definition: WPSCell.h:54
WPSCellFormat::CompareFormat
a comparaison structure used to store data
Definition: WPSCell.h:245
WPSCellFormat::setProtected
void setProtected(bool fl)
returns true if the cell is protected
Definition: WPSCell.h:196
WPSCellFormat::wrapping
Wrapping wrapping() const
returns the wrapping
Definition: WPSCell.h:128
WPSCellFormat::Wrapping
Wrapping
the wrapping
Definition: WPSCell.h:52
WPSCellFormat::getDTFormat
std::string getDTFormat() const
returns the date/time format ( if set)
Definition: WPSCell.h:160
WPSCellFormat::m_bordersList
std::vector< WPSBorder > m_bordersList
the cell border WPSBorder::Pos
Definition: WPSCell.h:270
WPSCellFormat::setBackgroundColor
void setBackgroundColor(WPSColor const &color)
set the background color
Definition: WPSCell.h:233
WPSCellFormat::VALIGN_TOP
Definition: WPSCell.h:50
libwps_internal.h
WPSCellFormat::setWrapping
void setWrapping(Wrapping align)
sets the wrapping
Definition: WPSCell.h:133
WPSCellFormat::F_BOOLEAN
Definition: WPSCell.h:54
WPSCellFormat::F_UNKNOWN
Definition: WPSCell.h:54
WPSCell::isVerticalSet
bool isVerticalSet() const
returns true if the vertical is fixed
Definition: WPSCell.h:316
WPSCell::Compare::m_coord
int m_coord
the coord to compare
Definition: WPSCell.h:408
WPSCellFormat::vAlignement
VerticalAlignment vAlignement() const
returns the vertical alignement
Definition: WPSCell.h:118
WPSCellFormat::m_subFormat
int m_subFormat
the sub format
Definition: WPSCell.h:274
WPSBox2< float >
WPSCell::Compare::Compare
Compare(int dim)
Definition: WPSCell.h:365
WPSCell::~WPSCell
~WPSCell() override
destructor
Definition: WPSCell.h:300
WPSCell::Compare::Point::getPos
float getPos(int coord) const
Definition: WPSCell.h:373
WPSCell::Compare::Point::getSize
float getSize(int coord) const
Definition: WPSCell.h:379
WPSCell::Compare::Point
small structure to define a cell point
Definition: WPSCell.h:368
WPSCellFormat::getTextRotation
int getTextRotation() const
returns the text rotation angle
Definition: WPSCell.h:139
WPSCell::sendContent
virtual bool sendContent(WPSListenerPtr &listener)=0
call when the content of a cell must be send
WPSCellFormat::convertDTFormat
static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector)
convert a DTFormat in a propertyList
Definition: WPSCell.cpp:35
WPSCellFormat::resetBorders
void resetBorders()
reset the border
Definition: WPSCell.h:214
WPSCellFormat::HALIGN_DEFAULT
Definition: WPSCell.h:47
WPSCell::setPosition
void setPosition(Vec2i posi)
set the cell positions : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:336
WPSCellFormat::hasBasicFormat
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: WPSCell.h:85
WPSColor
the class to store a color
Definition: libwps_internal.h:280
WPSCellFormat::isProtected
bool isProtected() const
returns true if the cell is protected
Definition: WPSCell.h:190
WPSCellFormat::CompareFormat::operator()
bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
comparaison function
Definition: WPSCell.h:250
WPSCell::m_position
Vec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:416
WPSCell::Compare::Point::m_cell
WPSCell const * m_cell
Definition: WPSCell.h:384
WPSCellFormat::m_protected
bool m_protected
cell protected
Definition: WPSCell.h:280
WPSCellFormat::getFormat
FormatType getFormat() const
returns the format type
Definition: WPSCell.h:150
WPSCellFormat::digits
int digits() const
returns the number of digits ( for a number)
Definition: WPSCell.h:179
WPSCellFormat::setHAlignement
void setHAlignement(HorizontalAlignment align)
sets the horizontal alignement
Definition: WPSCell.h:112
WPSCellFormat::getValueType
std::string getValueType() const
returns a value type
Definition: WPSCell.cpp:242
WPSCell::send
virtual bool send(WPSListenerPtr &listener)=0
call when a cell must be send
WPSCellFormat::HALIGN_CENTER
Definition: WPSCell.h:46
WPSCellFormat::HALIGN_FULL
Definition: WPSCell.h:47
WPSCell::Compare::Point::m_which
int m_which
Definition: WPSCell.h:383
WPSCellFormat::m_font
WPSFont m_font
the cell font ( used in spreadsheet code )
Definition: WPSCell.h:260
WPSCell::position
Vec2i const & position() const
position accessor
Definition: WPSCell.h:331
WPSFont.h
WPSCellFormat::m_backgroundColor
WPSColor m_backgroundColor
the backgroung color
Definition: WPSCell.h:282
WPSCellFormat::getNumberingProperties
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the number style
Definition: WPSCell.cpp:277
WPSCellFormat::~WPSCellFormat
virtual ~WPSCellFormat()
destructor
Definition: WPSCell.h:83
WPSTable
Definition: WPSTable.h:156
WPSCell::numSpannedCells
Vec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: WPSCell.h:342
Vec2< int >
WPSCell::m_verticalSet
bool m_verticalSet
true if y size is fixed
Definition: WPSCell.h:414
WPSCell::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSCell const &cell)
operator<<
Definition: WPSCell.cpp:536
WPSCell::m_box
WPSBox2f m_box
the cell bounding box (unit in point)
Definition: WPSCell.h:412
WPSCellFormat::setTextRotation
void setTextRotation(int rotation)
sets the text rotation angle
Definition: WPSCell.h:144
WPSCellFormat::HALIGN_RIGHT
Definition: WPSCell.h:46
WPSBox2::min
Vec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:725
WPSCellFormat::HorizontalAlignment
HorizontalAlignment
the default horizontal alignement.
Definition: WPSCell.h:46
WPSCellFormat::compare
int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const
a comparison function
Definition: WPSCell.cpp:362
WPSCellFormat::setBorders
void setBorders(std::vector< WPSBorder > const &newBorders)
sets the cell borders
Definition: WPSCell.h:222
WPSCellFormat::VerticalAlignment
VerticalAlignment
the default vertical alignement.
Definition: WPSCell.h:50
WPSCellFormat::getFont
WPSFont const & getFont() const
returns the font
Definition: WPSCell.h:97
WPSCellFormat::CompareFormat::CompareFormat
CompareFormat()
constructor
Definition: WPSCell.h:248
WPSCell::position
Vec2i & position()
position accessor
Definition: WPSCell.h:326
WPSCell::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:525
WPSCellFormat::WPSCellFormat
WPSCellFormat()
constructor
Definition: WPSCell.h:69
WPSCellFormat::WRAP_DEFAULT
Definition: WPSCell.h:52
WPSCellFormat::getSubFormat
int getSubFormat() const
returns the subformat type
Definition: WPSCell.h:155