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(), m_hAlign(HALIGN_DEFAULT), m_vAlign(VALIGN_DEFAULT), m_wrapping(WRAP_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()) { }
72 virtual ~WPSCellFormat() {}
74 bool hasBasicFormat() const
75 {
76 return m_format==F_TEXT || m_format==F_UNKNOWN;
77 }
79 std::string getValueType() const;
81 void addTo(librevenge::RVNGPropertyList &propList) const;
83 bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const;
84
86 WPSFont const &getFont() const
87 {
88 return m_font;
89 }
91 void setFont(WPSFont const &font)
92 {
93 m_font=font;
94 }
96 HorizontalAlignment hAlignement() const
97 {
98 return m_hAlign;
99 }
101 void setHAlignement(HorizontalAlignment align)
102 {
103 m_hAlign = align;
104 }
105
107 VerticalAlignment vAlignement() const
108 {
109 return m_vAlign;
110 }
112 void setVAlignement(VerticalAlignment align)
113 {
114 m_vAlign = align;
115 }
117 Wrapping wrapping() const
118 {
119 return m_wrapping;
120 }
122 void setWrapping(Wrapping align)
123 {
124 m_wrapping = align;
125 }
126
128 int getTextRotation() const
129 {
130 return m_rotation;
131 }
133 void setTextRotation(int rotation)
134 {
135 m_rotation = rotation;
136 }
137
139 FormatType getFormat() const
140 {
141 return m_format;
142 }
144 int getSubFormat() const
145 {
146 return m_subFormat;
147 }
149 std::string getDTFormat() const
150 {
151 return m_DTFormat;
152 }
154 void setFormat(FormatType form, int subForm=0)
155 {
156 m_format = form;
157 m_subFormat = subForm;
158 }
160 void setDTFormat(FormatType form, std::string const &dtFormat="")
161 {
162 m_format = form;
163 m_subFormat = 0;
164 m_DTFormat = dtFormat;
165 }
166
168 int digits() const
169 {
170 return m_digits;
171 }
173 void setDigits(int newDigit)
174 {
175 m_digits = newDigit;
176 }
177
179 bool isProtected() const
180 {
181 return m_protected;
182 }
183
185 void setProtected(bool fl)
186 {
187 m_protected = fl;
188 }
189
191 bool hasBorders() const
192 {
193 return m_bordersList.size() != 0;
194 }
195
197 std::vector<WPSBorder> const &borders() const
198 {
199 return m_bordersList;
200 }
201
203 void resetBorders()
204 {
205 m_bordersList.resize(0);
206 }
207
209 void setBorders(int wh, WPSBorder const &border);
211 void setBorders(std::vector<WPSBorder> const &newBorders)
212 {
213 m_bordersList=newBorders;
214 }
215
217 WPSColor backgroundColor() const
218 {
219 return m_backgroundColor;
220 }
222 void setBackgroundColor(WPSColor const &color)
223 {
224 m_backgroundColor = color;
225 }
226
228 int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const;
229
231 friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
232
234 struct CompareFormat
235 {
237 CompareFormat() {}
239 bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
240 {
241 return c1.compare(c2, true) < 0;
242 }
243 };
244
245 protected:
247 static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
249 WPSFont m_font;
251 HorizontalAlignment m_hAlign;
253 VerticalAlignment m_vAlign;
255 Wrapping m_wrapping;
257 int m_rotation;
259 std::vector<WPSBorder> m_bordersList;
261 FormatType m_format;
263 int m_subFormat;
265 std::string m_DTFormat;
267 int m_digits;
269 bool m_protected;
271 WPSColor m_backgroundColor;
272 };
273
274 class WPSTable;
275
277 class WPSCell : public WPSCellFormat
278 {
279 friend class WPSTable;
280 public:
282 WPSCell() : WPSCellFormat(), m_box(), m_verticalSet(true), m_position(0,0), m_numberCellSpanned(1,1) {}
284 virtual ~WPSCell() {}
285
287 void addTo(librevenge::RVNGPropertyList &propList) const;
288
290 void setBox(WPSBox2f const &b)
291 {
292 m_box = b;
293 }
295 WPSBox2f const &box() const
296 {
297 return m_box;
298 }
300 bool isVerticalSet() const
301 {
302 return m_verticalSet;
303 }
305 void setVerticalSet(bool verticalSet)
306 {
307 m_verticalSet = verticalSet;
308 }
310 Vec2i &position()
311 {
312 return m_position;
313 }
315 Vec2i const &position() const
316 {
317 return m_position;
318 }
320 void setPosition(Vec2i posi)
321 {
322 m_position = posi;
323 }
324
326 Vec2i const &numSpannedCells() const
327 {
328 return m_numberCellSpanned;
329 }
331 void setNumSpannedCells(Vec2i numSpanned)
332 {
333 m_numberCellSpanned=numSpanned;
334 }
335
337 virtual bool send(WPSListenerPtr &listener) = 0;
338
340 virtual bool sendContent(WPSListenerPtr &listener) = 0;
341
343 friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
344
345 protected:
347 struct Compare
348 {
349 explicit Compare(int dim) : m_coord(dim) {}
351 struct Point
352 {
353 Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
354 float getPos(int coord) const
355 {
356 if (m_which)
357 return m_cell->box().max()[coord];
358 return m_cell->box().min()[coord];
359 }
360 float getSize(int coord) const
361 {
362 return m_cell->box().size()[coord];
363 }
364 int m_which;
365 WPSCell const *m_cell;
366 };
367
369 bool operator()(Point const &c1, Point const &c2) const
370 {
371 float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
372 if (diffF < 0) return true;
373 if (diffF > 0) return false;
374 int diff = c2.m_which - c1.m_which;
375 if (diff) return (diff < 0);
376 diffF = c1.m_cell->box().size()[m_coord]
377 - c2.m_cell->box().size()[m_coord];
378 if (diffF < 0) return true;
379 if (diffF > 0) return false;
380 if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
381 #ifdef _WIN64
382 return ((__int64)c1.m_cell < (__int64)c2.m_cell);
383 #else
384 return long(c1.m_cell) < long(c2.m_cell);
385 #endif
386 }
387
389 int m_coord;
390 };
391
393 WPSBox2f m_box;
395 bool m_verticalSet;
397 Vec2i m_position;
399 Vec2i m_numberCellSpanned;
400 };
401
402 #endif
403 /* 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:191
WPSCellFormat::m_digits
int m_digits
the number of digits
Definition: WPSCell.h:267
WPSCellFormat::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
operator<<
Definition: WPSCell.cpp:391
WPSCellFormat::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSCell.cpp:156
WPSBorder
a border list
Definition: libwps_internal.h:379
WPSCell::Compare
a comparaison structure used retrieve the rows and the columns
Definition: WPSCell.h:347
WPSCellFormat::backgroundColor
WPSColor backgroundColor() const
returns the background color
Definition: WPSCell.h:217
WPSCellFormat::hAlignement
HorizontalAlignment hAlignement() const
returns the horizontal alignement
Definition: WPSCell.h:96
WPSBox2::size
Vec2< T > size() const
the box size
Definition: libwps_internal.h:771
WPSCell::Compare::operator()
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: WPSCell.h:369
WPSCell::Compare::Point::Point
Point(int wh, WPSCell const *cell)
Definition: WPSCell.h:353
WPSCell::m_numberCellSpanned
Vec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: WPSCell.h:399
WPSCellFormat::setDigits
void setDigits(int newDigit)
set the number of digits ( for a number)
Definition: WPSCell.h:173
WPSCell::box
WPSBox2f const & box() const
return the bounding box
Definition: WPSCell.h:295
WPSCellFormat::m_wrapping
Wrapping m_wrapping
the wrapping : by default nothing
Definition: WPSCell.h:255
WPSCell::~WPSCell
virtual ~WPSCell()
destructor
Definition: WPSCell.h:284
WPSCellFormat::m_vAlign
VerticalAlignment m_vAlign
the cell vertical alignement : by default nothing
Definition: WPSCell.h:253
WPSCellFormat::VALIGN_BOTTOM
Definition: WPSCell.h:50
WPSCellFormat::setFormat
void setFormat(FormatType form, int subForm=0)
sets the format type
Definition: WPSCell.h:154
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:261
WPSCell::setBox
void setBox(WPSBox2f const &b)
set the bounding box (units in point)
Definition: WPSCell.h:290
WPSCellFormat::setBorders
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=WPSBorder::LeftBit|...
Definition: WPSCell.cpp:136
WPSCellFormat::m_rotation
int m_rotation
the text rotation
Definition: WPSCell.h:257
WPSCell::WPSCell
WPSCell()
constructor
Definition: WPSCell.h:282
WPSCell::setVerticalSet
void setVerticalSet(bool verticalSet)
fixes or not the vertical size
Definition: WPSCell.h:305
WPSCellFormat::VALIGN_CENTER
Definition: WPSCell.h:50
WPSCellFormat::m_hAlign
HorizontalAlignment m_hAlign
the cell alignement : by default nothing
Definition: WPSCell.h:251
WPSCellFormat::m_DTFormat
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: WPSCell.h:265
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:160
WPSCellFormat::setVAlignement
void setVAlignement(VerticalAlignment align)
sets the vertical alignement
Definition: WPSCell.h:112
WPSCellFormat::setFont
void setFont(WPSFont const &font)
sets the font
Definition: WPSCell.h:91
WPSCellFormat::borders
std::vector< WPSBorder > const & borders() const
return the cell border: libwps::LeftBit | ...
Definition: WPSCell.h:197
WPSCellFormat::F_NUMBER
Definition: WPSCell.h:54
WPSCell
a structure used to defined the cell position, and a format
Definition: WPSCell.h:277
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:331
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:234
WPSCellFormat::setProtected
void setProtected(bool fl)
returns true if the cell is protected
Definition: WPSCell.h:185
WPSCellFormat::wrapping
Wrapping wrapping() const
returns the wrapping
Definition: WPSCell.h:117
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:149
WPSCellFormat::m_bordersList
std::vector< WPSBorder > m_bordersList
the cell border WPSBorder::Pos
Definition: WPSCell.h:259
WPSListenerPtr
shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:106
WPSCellFormat::setBackgroundColor
void setBackgroundColor(WPSColor const &color)
set the background color
Definition: WPSCell.h:222
WPSCellFormat::VALIGN_TOP
Definition: WPSCell.h:50
libwps_internal.h
WPSCellFormat::setWrapping
void setWrapping(Wrapping align)
sets the wrapping
Definition: WPSCell.h:122
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:300
WPSCell::Compare::m_coord
int m_coord
the coord to compare
Definition: WPSCell.h:389
WPSCellFormat::vAlignement
VerticalAlignment vAlignement() const
returns the vertical alignement
Definition: WPSCell.h:107
WPSCellFormat::m_subFormat
int m_subFormat
the sub format
Definition: WPSCell.h:263
WPSBox2< float >
WPSCell::Compare::Compare
Compare(int dim)
Definition: WPSCell.h:349
WPSCell::Compare::Point::getPos
float getPos(int coord) const
Definition: WPSCell.h:354
WPSCell::Compare::Point::getSize
float getSize(int coord) const
Definition: WPSCell.h:360
WPSCell::Compare::Point
small structure to define a cell point
Definition: WPSCell.h:351
WPSCellFormat::getTextRotation
int getTextRotation() const
returns the text rotation angle
Definition: WPSCell.h:128
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:203
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:320
WPSCellFormat::hasBasicFormat
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: WPSCell.h:74
WPSColor
the class to store a color
Definition: libwps_internal.h:273
WPSCellFormat::isProtected
bool isProtected() const
returns true if the cell is protected
Definition: WPSCell.h:179
WPSCellFormat::CompareFormat::operator()
bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const
comparaison function
Definition: WPSCell.h:239
WPSCell::m_position
Vec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: WPSCell.h:397
WPSCell::Compare::Point::m_cell
WPSCell const * m_cell
Definition: WPSCell.h:365
WPSCellFormat::m_protected
bool m_protected
cell protected
Definition: WPSCell.h:269
WPSCellFormat::getFormat
FormatType getFormat() const
returns the format type
Definition: WPSCell.h:139
WPSCellFormat::digits
int digits() const
returns the number of digits ( for a number)
Definition: WPSCell.h:168
WPSCellFormat::setHAlignement
void setHAlignement(HorizontalAlignment align)
sets the horizontal alignement
Definition: WPSCell.h:101
WPSCellFormat::getValueType
std::string getValueType() const
returns a value type
Definition: WPSCell.cpp:239
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:364
WPSCellFormat::m_font
WPSFont m_font
the cell font ( used in spreadsheet code )
Definition: WPSCell.h:249
WPSCell::position
Vec2i const & position() const
position accessor
Definition: WPSCell.h:315
WPSFont.h
WPSCellFormat::m_backgroundColor
WPSColor m_backgroundColor
the backgroung color
Definition: WPSCell.h:271
WPSCellFormat::getNumberingProperties
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the number style
Definition: WPSCell.cpp:274
WPSCellFormat::~WPSCellFormat
virtual ~WPSCellFormat()
destructor
Definition: WPSCell.h:72
WPSTable
Definition: WPSTable.h:156
WPSCell::numSpannedCells
Vec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: WPSCell.h:326
Vec2< int >
WPSCell::m_verticalSet
bool m_verticalSet
true if y size is fixed
Definition: WPSCell.h:395
WPSCell::m_box
WPSBox2f m_box
the cell bounding box (unit in point)
Definition: WPSCell.h:393
WPSCellFormat::setTextRotation
void setTextRotation(int rotation)
sets the text rotation angle
Definition: WPSCell.h:133
WPSCellFormat::HALIGN_RIGHT
Definition: WPSCell.h:46
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:359
WPSCellFormat::setBorders
void setBorders(std::vector< WPSBorder > const &newBorders)
sets the cell borders
Definition: WPSCell.h:211
WPSCellFormat::VerticalAlignment
VerticalAlignment
the default vertical alignement.
Definition: WPSCell.h:50
WPSCellFormat::getFont
WPSFont const & getFont() const
returns the font
Definition: WPSCell.h:86
WPSCellFormat::CompareFormat::CompareFormat
CompareFormat()
constructor
Definition: WPSCell.h:237
WPSCell::position
Vec2i & position()
position accessor
Definition: WPSCell.h:310
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:144