MWAWCell.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33 
38 #ifndef MWAW_CELL_H
39 # define MWAW_CELL_H
40 
41 #include <string>
42 #include <vector>
43 
44 #include "libmwaw_internal.hxx"
45 
46 #include "MWAWEntry.hxx"
47 #include "MWAWFont.hxx"
48 
49 class MWAWTable;
50 
52 class MWAWCell
53 {
54 public:
60  struct Format {
63  : m_format(F_UNKNOWN)
64  , m_numberFormat(F_NUMBER_UNKNOWN)
65  , m_digits(-1)
66  , m_integerDigits(-1)
67  , m_numeratorDigits(-1)
69  , m_thousandHasSeparator(false)
71  , m_currencySymbol("$")
72  , m_DTFormat("")
73  {
74  }
76  virtual ~Format();
78  bool hasBasicFormat() const
79  {
80  return m_format==F_TEXT || m_format==F_UNKNOWN;
81  }
83  std::string getValueType() const;
85  bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const;
87  friend std::ostream &operator<<(std::ostream &o, Format const &format);
89  int compare(Format const &format) const;
90 
96  int m_digits;
108  std::string m_currencySymbol;
110  std::string m_DTFormat;
111  };
113  struct CompareFormat {
117  bool operator()(Format const &c1, Format const &c2) const
118  {
119  return c1.compare(c2) < 0;
120  }
121  };
127  };
128 
132 
135 
138  : m_position(0,0)
139  , m_numberCellSpanned(1,1)
140  , m_bdBox()
141  , m_bdSize()
142  , m_format()
143  , m_font(3,12)
144  , m_fontSet(false)
145  , m_hAlign(HALIGN_DEFAULT)
146  , m_vAlign(VALIGN_DEFAULT)
147  , m_backgroundColor(MWAWColor::white())
148  , m_protected(false)
149  , m_bordersList()
151  , m_extraLineType() { }
152 
154  virtual ~MWAWCell() {}
155 
157  void addTo(librevenge::RVNGPropertyList &propList, std::shared_ptr<MWAWFontConverter> fontConverter) const;
158 
160  friend std::ostream &operator<<(std::ostream &o, MWAWCell const &cell);
161 
162  // interface with MWAWTable:
163 
168  virtual bool send(MWAWListenerPtr listener, MWAWTable &table);
173  virtual bool sendContent(MWAWListenerPtr listener, MWAWTable &table);
174 
175  // position
176 
178  MWAWVec2i const &position() const
179  {
180  return m_position;
181  }
184  {
185  m_position = posi;
186  }
187 
189  MWAWVec2i const &numSpannedCells() const
190  {
191  return m_numberCellSpanned;
192  }
194  void setNumSpannedCells(MWAWVec2i numSpanned)
195  {
196  m_numberCellSpanned=numSpanned;
197  }
198 
200  MWAWBox2f const &bdBox() const
201  {
202  return m_bdBox;
203  }
205  void setBdBox(MWAWBox2f box)
206  {
207  m_bdBox = box;
208  }
209 
211  MWAWVec2f const &bdSize() const
212  {
213  return m_bdSize;
214  }
217  {
218  m_bdSize = sz;
219  }
221  static std::string getBasicCellName(MWAWVec2i const &pos);
223  static std::string getCellName(MWAWVec2i const &pos, MWAWVec2b const &absolute);
224 
226  static std::string getColumnName(int col);
227 
228  // format
229 
231  Format const &getFormat() const
232  {
233  return m_format;
234  }
236  void setFormat(Format const &format)
237  {
238  m_format=format;
239  }
240 
242  bool isFontSet() const
243  {
244  return m_fontSet;
245  }
248  {
249  return m_font;
250  }
252  void setFont(MWAWFont const &font, bool isDefault=false)
253  {
254  m_font=font;
255  m_fontSet=!isDefault;
256  }
257 
259  bool isProtected() const
260  {
261  return m_protected;
262  }
264  void setProtected(bool fl)
265  {
266  m_protected = fl;
267  }
268 
271  {
272  return m_hAlign;
273  }
276  {
277  m_hAlign = align;
278  }
279 
282  {
283  return m_vAlign;
284  }
287  {
288  m_vAlign = align;
289  }
290 
292  bool hasBorders() const
293  {
294  return m_bordersList.size() != 0;
295  }
297  std::vector<MWAWBorder> const &borders() const
298  {
299  return m_bordersList;
300  }
301 
304  {
305  m_bordersList.resize(0);
306  }
308  void setBorders(int wh, MWAWBorder const &border);
309 
312  {
313  return m_backgroundColor;
314  }
317  {
318  m_backgroundColor = color;
319  }
321  bool hasExtraLine() const
322  {
324  }
327  {
328  return m_extraLine;
329  }
331  MWAWBorder const &extraLineType() const
332  {
333  return m_extraLineType;
334  }
336  void setExtraLine(ExtraLine extrLine, MWAWBorder const &type=MWAWBorder())
337  {
338  m_extraLine = extrLine;
339  m_extraLineType=type;
340  }
341 protected:
350 
356  bool m_fontSet;
365 
367  std::vector<MWAWBorder> m_bordersList;
372 };
373 
376 {
377 public:
380  enum Type { F_Operator, F_Function, F_Cell, F_CellList, F_Long, F_Double, F_Text };
383  : m_type(F_Text)
384  , m_content("")
385  , m_longValue(0)
386  , m_doubleValue(0)
387  , m_sheet("")
388  {
389  for (auto &pos : m_position) pos=MWAWVec2i(0,0);
390  for (auto &rel : m_positionRelative) rel=MWAWVec2b(false,false);
391  }
393  librevenge::RVNGPropertyList getPropertyList(MWAWFontConverter &fontConverter, int fontId) const;
395  friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
399  std::string m_content;
401  double m_longValue;
407  MWAWVec2b m_positionRelative[2];
409  std::string m_sheet;
410  };
411 
413  enum Type { C_NONE, C_TEXT, C_NUMBER, C_FORMULA, C_UNKNOWN };
416  : m_contentType(C_UNKNOWN)
417  , m_value(0.0)
418  , m_valueSet(false)
419  , m_textEntry()
420  , m_formula() { }
424  friend std::ostream &operator<<(std::ostream &o, MWAWCellContent const &cell);
425 
427  bool empty() const
428  {
429  if (m_contentType == C_NUMBER) return false;
430  if (m_contentType == C_TEXT && m_textEntry.valid()) return false;
431  if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
432  return true;
433  }
435  void setValue(double value)
436  {
437  m_value = value;
438  m_valueSet = true;
439  }
441  bool isValueSet() const
442  {
443  return m_valueSet;
444  }
446  bool hasText() const
447  {
448  return m_textEntry.valid();
449  }
452  static bool double2Date(double val, int &Y, int &M, int &D);
454  static bool double2Time(double val, int &H, int &M, int &S);
456  static bool double2String(double val, MWAWCell::Format const &format, std::string &str);
458  static bool date2Double(int Y, int M, int D, double &val);
462  double m_value;
468  std::vector<FormulaInstruction> m_formula;
469 };
470 
471 #endif
472 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWVec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: MWAWCell.hxx:189
MWAWVec2i const & position() const
position accessor
Definition: MWAWCell.hxx:178
small class use to define a formula instruction
Definition: MWAWCell.hxx:379
static std::string getBasicCellName(MWAWVec2i const &pos)
return the name of a cell (given row and column) : 0,0 -> A1, 0,1 -> A2...
Definition: MWAWCell.cxx:342
double m_doubleValue
value ( if type==F_Double )
Definition: MWAWCell.hxx:403
Type
the different types of cell&#39;s field
Definition: MWAWCell.hxx:413
MWAWVec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: MWAWCell.hxx:343
MWAWFont m_font
the cell font
Definition: MWAWCell.hxx:354
MWAWFont getFont() const
returns the font
Definition: MWAWCell.hxx:247
MWAWBorder m_extraLineType
extra line type
Definition: MWAWCell.hxx:371
void setFormat(Format const &format)
set the cell format
Definition: MWAWCell.hxx:236
Format()
constructor
Definition: MWAWCell.hxx:62
void setFont(MWAWFont const &font, bool isDefault=false)
sets the fonts
Definition: MWAWCell.hxx:252
virtual bool sendContent(MWAWListenerPtr listener, MWAWTable &table)
function called when the content of a cell must be send to the listener, ie.
Definition: MWAWCell.cxx:496
void setBackgroundColor(MWAWColor color)
sets the background color
Definition: MWAWCell.hxx:316
Definition: MWAWCell.hxx:56
MWAWCell()
constructor
Definition: MWAWCell.hxx:137
a comparaison structure used to store data
Definition: MWAWCell.hxx:113
int compare(Format const &format) const
a comparison function
Definition: MWAWCell.cxx:230
Definition: MWAWCell.hxx:58
Definition: MWAWCell.hxx:56
std::shared_ptr< MWAWListener > MWAWListenerPtr
a smart pointer of MWAWListener
Definition: libmwaw_internal.hxx:549
MWAWCellContent()
constructor
Definition: MWAWCell.hxx:415
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the numbering style
Definition: MWAWCell.cxx:82
a structure uses to define the format of a cell content
Definition: MWAWCell.hxx:60
MWAWBox2f const & bdBox() const
bdbox accessor
Definition: MWAWCell.hxx:200
Definition: MWAWCell.hxx:58
virtual ~Format()
destructor
Definition: MWAWCell.cxx:54
Definition: MWAWCell.hxx:56
bool hasBorders() const
return true if the cell has some border
Definition: MWAWCell.hxx:292
Definition: MWAWCell.hxx:58
void setProtected(bool fl)
sets the cell&#39;s protected flag
Definition: MWAWCell.hxx:264
Definition: MWAWCell.hxx:131
bool isFontSet() const
returns true if the font has been set
Definition: MWAWCell.hxx:242
std::vector< MWAWBorder > m_bordersList
the cell border MWAWBorder::Pos
Definition: MWAWCell.hxx:367
virtual bool send(MWAWListenerPtr listener, MWAWTable &table)
function called when a cell is send by MWAWTable to send a cell to a listener.
Definition: MWAWCell.cxx:487
VerticalAlignment m_vAlign
the vertical cell alignment : by default nothing
Definition: MWAWCell.hxx:360
MWAWEntry m_textEntry
the cell string
Definition: MWAWCell.hxx:466
std::string m_currencySymbol
the currency symbol ( default &#39;$&#39;)
Definition: MWAWCell.hxx:108
Type m_type
the type
Definition: MWAWCell.hxx:397
void setValue(double value)
sets the double value
Definition: MWAWCell.hxx:435
std::string m_sheet
the sheet name (if not empty)
Definition: MWAWCell.hxx:409
Definition: MWAWCell.hxx:58
HorizontalAlignment hAlignment() const
returns the horizontal alignment
Definition: MWAWCell.hxx:270
a class used to recreate the table structure using cell informations, ....
Definition: MWAWTable.hxx:51
MWAWVec2< int > MWAWVec2i
MWAWVec2 of int.
Definition: libmwaw_internal.hxx:834
bool m_protected
cell protected
Definition: MWAWCell.hxx:364
bool m_thousandHasSeparator
true if we must separate the thousand
Definition: MWAWCell.hxx:104
void setHAlignment(HorizontalAlignment align)
sets the horizontal alignment
Definition: MWAWCell.hxx:275
static std::string getColumnName(int col)
return the column name
Definition: MWAWCell.cxx:332
Definition: MWAWCell.hxx:58
ExtraLine extraLine() const
returns the extra lines
Definition: MWAWCell.hxx:326
HorizontalAlignment
the default horizontal alignment.
Definition: MWAWCell.hxx:125
bool m_parenthesesForNegative
true if we use parenthese to print negative number
Definition: MWAWCell.hxx:106
a structure used to define a cell and its format
Definition: MWAWCell.hxx:52
the class to store a color
Definition: libmwaw_internal.hxx:192
MWAWColor backgroundColor() const
returns the background color
Definition: MWAWCell.hxx:311
Format m_format
the cell format
Definition: MWAWCell.hxx:352
double m_value
the cell value
Definition: MWAWCell.hxx:462
Definition: MWAWCell.hxx:134
std::vector< FormulaInstruction > m_formula
the formula list of instruction
Definition: MWAWCell.hxx:468
small class use to define a sheet cell content
Definition: MWAWCell.hxx:375
FormatType
the different format of a cell&#39;s content
Definition: MWAWCell.hxx:56
MWAWVec2f m_bdSize
the cell bounding size : unit point
Definition: MWAWCell.hxx:349
MWAWBox2f m_bdBox
the cell bounding box (unit in point)
Definition: MWAWCell.hxx:347
virtual ~MWAWCell()
destructor
Definition: MWAWCell.hxx:154
Class to store font.
Definition: MWAWFont.hxx:43
a border
Definition: libmwaw_internal.hxx:333
bool hasText() const
returns true if the text is set
Definition: MWAWCell.hxx:446
~MWAWCellContent()
destructor
Definition: MWAWCell.hxx:422
Definition: MWAWCell.hxx:58
void setBdSize(MWAWVec2f sz)
set the bdbox size(unit point)
Definition: MWAWCell.hxx:216
void setVAlignment(VerticalAlignment align)
sets the vertical alignment
Definition: MWAWCell.hxx:286
HorizontalAlignment m_hAlign
the cell alignment : by default nothing
Definition: MWAWCell.hxx:358
ExtraLine
an enum to defined potential internal line: E_Line1=TL to RB, E_Line2=BL to RT
Definition: MWAWCell.hxx:134
friend std::ostream & operator<<(std::ostream &o, Format const &format)
operator<<
Definition: MWAWCell.cxx:167
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: MWAWCell.hxx:78
Definition: MWAWCell.hxx:131
MWAWVec2< bool > MWAWVec2b
MWAWVec2 of bool.
Definition: libmwaw_internal.hxx:832
Definition: MWAWCell.hxx:126
std::string getValueType() const
returns a value type
Definition: MWAWCell.cxx:58
Format const & getFormat() const
returns the cell format
Definition: MWAWCell.hxx:231
Definition: MWAWCell.hxx:56
MWAWVec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: MWAWCell.hxx:345
FormatType m_format
the cell format : by default unknown
Definition: MWAWCell.hxx:92
void setExtraLine(ExtraLine extrLine, MWAWBorder const &type=MWAWBorder())
sets the extraline
Definition: MWAWCell.hxx:336
ExtraLine m_extraLine
extra line
Definition: MWAWCell.hxx:369
void resetBorders()
reset the border
Definition: MWAWCell.hxx:303
Type
Definition: MWAWCell.hxx:380
Definition: MWAWCell.hxx:134
void setPosition(MWAWVec2i posi)
set the cell positions : 0,0 -> A1, 0,1 -> A2
Definition: MWAWCell.hxx:183
VerticalAlignment vAlignment() const
returns the vertical alignment
Definition: MWAWCell.hxx:281
MWAWVec2f const & bdSize() const
bdbox size accessor
Definition: MWAWCell.hxx:211
int m_numeratorDigits
the number of numerator digits
Definition: MWAWCell.hxx:100
a namespace used to convert Mac font characters in unicode
Definition: MWAWFontConverter.hxx:62
Type m_contentType
the content type ( by default unknown )
Definition: MWAWCell.hxx:460
Definition: MWAWCell.hxx:56
Definition: MWAWCell.hxx:131
void setNumSpannedCells(MWAWVec2i numSpanned)
sets the number of spanned cells : MWAWVec2i(1,1) means 1 cellule
Definition: MWAWCell.hxx:194
Definition: MWAWCell.hxx:126
int m_digits
the number of digits
Definition: MWAWCell.hxx:96
Definition: MWAWCell.hxx:58
MWAWColor m_backgroundColor
the backgroung color
Definition: MWAWCell.hxx:362
NumberType m_numberFormat
the numeric format
Definition: MWAWCell.hxx:94
bool m_fontSet
a flag to know if the font has been set
Definition: MWAWCell.hxx:356
static std::string getCellName(MWAWVec2i const &pos, MWAWVec2b const &absolute)
return the name of a cell (given row and column) : 0,0 -> [.A1], 0,1 -> [.A2]
Definition: MWAWCell.cxx:359
bool hasExtraLine() const
returns true if we have some extra lines
Definition: MWAWCell.hxx:321
double m_longValue
value ( if type==F_Long )
Definition: MWAWCell.hxx:401
Definition: MWAWCell.hxx:134
CompareFormat()
constructor
Definition: MWAWCell.hxx:115
std::vector< MWAWBorder > const & borders() const
return the cell border: libmwaw::Left | ...
Definition: MWAWCell.hxx:297
MWAWBorder const & extraLineType() const
returns the extra line border
Definition: MWAWCell.hxx:331
bool m_valueSet
true if the value has been set
Definition: MWAWCell.hxx:464
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
void addTo(librevenge::RVNGPropertyList &propList, std::shared_ptr< MWAWFontConverter > fontConverter) const
adds to the propList
Definition: MWAWCell.cxx:255
bool empty() const
returns true if the cell has no content
Definition: MWAWCell.hxx:427
VerticalAlignment
the default vertical alignment.
Definition: MWAWCell.hxx:131
FormulaInstruction()
constructor
Definition: MWAWCell.hxx:382
NumberType
the different number format of a cell&#39;s content
Definition: MWAWCell.hxx:58
Definition: MWAWCell.hxx:125
std::string m_content
the content ( if type == F_Operator or type = F_Function or type==F_Text)
Definition: MWAWCell.hxx:399
int m_denominatorDigits
the number of denominator digits
Definition: MWAWCell.hxx:102
Definition: MWAWCell.hxx:131
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: MWAWCell.hxx:110
void setBdBox(MWAWBox2f box)
set the bdbox (unit point)
Definition: MWAWCell.hxx:205
Definition: MWAWCell.hxx:134
bool isValueSet() const
returns true if the value has been setted
Definition: MWAWCell.hxx:441
Definition: MWAWCell.hxx:125
bool operator()(Format const &c1, Format const &c2) const
comparaison function
Definition: MWAWCell.hxx:117
bool isProtected() const
returns true if the cell is protected
Definition: MWAWCell.hxx:259
int m_integerDigits
the number of main digits
Definition: MWAWCell.hxx:98
Definition: MWAWCell.hxx:125
Definition: MWAWCell.hxx:56
void setBorders(int wh, MWAWBorder const &border)
sets the cell border: wh=libmwaw::LeftBit|...
Definition: MWAWCell.cxx:379
bool isEmpty() const
returns true if the border is empty
Definition: libmwaw_internal.hxx:356

Generated for libmwaw by doxygen 1.8.11