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 {
64  {
65  }
67  virtual ~Format() {}
69  bool hasBasicFormat() const
70  {
71  return m_format==F_TEXT || m_format==F_UNKNOWN;
72  }
74  std::string getValueType() const;
76  bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const;
78  static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
80  friend std::ostream &operator<<(std::ostream &o, Format const &format);
82  int compare(Format const &format) const;
83 
89  int m_digits;
101  std::string m_currencySymbol;
103  std::string m_DTFormat;
104  };
106  struct CompareFormat {
110  bool operator()(Format const &c1, Format const &c2) const
111  {
112  return c1.compare(c2) < 0;
113  }
114  };
120  };
121 
125 
128 
132  m_backgroundColor(MWAWColor::white()), m_protected(false),
134 
136  virtual ~MWAWCell() {}
137 
139  void addTo(librevenge::RVNGPropertyList &propList, shared_ptr<MWAWFontConverter> fontConverter) const;
140 
142  friend std::ostream &operator<<(std::ostream &o, MWAWCell const &cell);
143 
144  // interface with MWAWTable:
145 
150  virtual bool send(MWAWListenerPtr listener, MWAWTable &table);
155  virtual bool sendContent(MWAWListenerPtr listener, MWAWTable &table);
156 
157  // position
158 
160  MWAWVec2i const &position() const
161  {
162  return m_position;
163  }
166  {
167  m_position = posi;
168  }
169 
171  MWAWVec2i const &numSpannedCells() const
172  {
173  return m_numberCellSpanned;
174  }
176  void setNumSpannedCells(MWAWVec2i numSpanned)
177  {
178  m_numberCellSpanned=numSpanned;
179  }
180 
182  MWAWBox2f const &bdBox() const
183  {
184  return m_bdBox;
185  }
187  void setBdBox(MWAWBox2f box)
188  {
189  m_bdBox = box;
190  }
191 
193  MWAWVec2f const &bdSize() const
194  {
195  return m_bdSize;
196  }
199  {
200  m_bdSize = sz;
201  }
203  static std::string getBasicCellName(MWAWVec2i const &pos);
205  static std::string getCellName(MWAWVec2i const &pos, MWAWVec2b const &absolute);
206 
208  static std::string getColumnName(int col);
209 
210  // format
211 
213  Format const &getFormat() const
214  {
215  return m_format;
216  }
218  void setFormat(Format const &format)
219  {
220  m_format=format;
221  }
222 
224  bool isFontSet() const
225  {
226  return m_fontSet;
227  }
230  {
231  return m_font;
232  }
234  void setFont(MWAWFont const &font, bool isDefault=false)
235  {
236  m_font=font;
237  m_fontSet=!isDefault;
238  }
239 
241  bool isProtected() const
242  {
243  return m_protected;
244  }
246  void setProtected(bool fl)
247  {
248  m_protected = fl;
249  }
250 
253  {
254  return m_hAlign;
255  }
258  {
259  m_hAlign = align;
260  }
261 
264  {
265  return m_vAlign;
266  }
269  {
270  m_vAlign = align;
271  }
272 
274  bool hasBorders() const
275  {
276  return m_bordersList.size() != 0;
277  }
279  std::vector<MWAWBorder> const &borders() const
280  {
281  return m_bordersList;
282  }
283 
286  {
287  m_bordersList.resize(0);
288  }
290  void setBorders(int wh, MWAWBorder const &border);
291 
294  {
295  return m_backgroundColor;
296  }
299  {
300  m_backgroundColor = color;
301  }
303  bool hasExtraLine() const
304  {
306  }
309  {
310  return m_extraLine;
311  }
313  MWAWBorder const &extraLineType() const
314  {
315  return m_extraLineType;
316  }
318  void setExtraLine(ExtraLine extrLine, MWAWBorder const &type=MWAWBorder())
319  {
320  m_extraLine = extrLine;
321  m_extraLineType=type;
322  }
323 protected:
332 
338  bool m_fontSet;
347 
349  std::vector<MWAWBorder> m_bordersList;
354 };
355 
358 {
359 public:
365  {
366  for (int i=0; i<2; ++i) {
367  m_position[i]=MWAWVec2i(0,0);
368  m_positionRelative[i]=MWAWVec2b(false,false);
369  }
370  }
372  librevenge::RVNGPropertyList getPropertyList(MWAWFontConverter &fontConverter, int fontId) const;
374  friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
378  std::string m_content;
380  double m_longValue;
388  std::string m_sheet;
389  };
390 
398  friend std::ostream &operator<<(std::ostream &o, MWAWCellContent const &cell);
399 
401  bool empty() const
402  {
403  if (m_contentType == C_NUMBER) return false;
404  if (m_contentType == C_TEXT && m_textEntry.valid()) return false;
405  if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
406  return true;
407  }
409  void setValue(double value)
410  {
411  m_value = value;
412  m_valueSet = true;
413  }
415  bool isValueSet() const
416  {
417  return m_valueSet;
418  }
420  bool hasText() const
421  {
422  return m_textEntry.valid();
423  }
426  static bool double2Date(double val, int &Y, int &M, int &D);
428  static bool double2Time(double val, int &H, int &M, int &S);
430  static bool double2String(double val, MWAWCell::Format const &format, std::string &str);
432  static bool date2Double(int Y, int M, int D, double &val);
436  double m_value;
442  std::vector<FormulaInstruction> m_formula;
443 };
444 
445 #endif
446 // 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:171
shared_ptr< MWAWListener > MWAWListenerPtr
a smart pointer of MWAWListener
Definition: libmwaw_internal.hxx:498
MWAWVec2i const & position() const
position accessor
Definition: MWAWCell.hxx:160
small class use to define a formula instruction
Definition: MWAWCell.hxx:361
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:419
double m_doubleValue
value ( if type==F_Double )
Definition: MWAWCell.hxx:382
Type
the different types of cell's field
Definition: MWAWCell.hxx:392
bool valid() const
returns true if the zone length is positive
Definition: MWAWEntry.hxx:87
MWAWVec2i m_position
the cell row and column : 0,0 -> A1, 0,1 -> A2
Definition: MWAWCell.hxx:325
MWAWFont m_font
the cell font
Definition: MWAWCell.hxx:336
friend std::ostream & operator<<(std::ostream &o, MWAWCell const &cell)
operator<<
Definition: MWAWCell.cxx:479
MWAWFont getFont() const
returns the font
Definition: MWAWCell.hxx:229
MWAWBorder m_extraLineType
extra line type
Definition: MWAWCell.hxx:353
void setFormat(Format const &format)
set the cell format
Definition: MWAWCell.hxx:218
Format()
constructor
Definition: MWAWCell.hxx:62
void setFont(MWAWFont const &font, bool isDefault=false)
sets the fonts
Definition: MWAWCell.hxx:234
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:567
void setBackgroundColor(MWAWColor color)
sets the background color
Definition: MWAWCell.hxx:298
Definition: MWAWCell.hxx:56
MWAWCell()
constructor
Definition: MWAWCell.hxx:130
a comparaison structure used to store data
Definition: MWAWCell.hxx:106
static bool double2Time(double val, int &H, int &M, int &S)
conversion beetween double: second since 0:00 and time
Definition: MWAWCell.cxx:656
Definition: MWAWCell.hxx:392
int compare(Format const &format) const
a comparison function
Definition: MWAWCell.cxx:311
Definition: MWAWCell.hxx:58
Definition: MWAWCell.hxx:56
librevenge::RVNGPropertyList getPropertyList(MWAWFontConverter &fontConverter, int fontId) const
returns a proplist corresponding to a instruction using a font converter to send the text ...
Definition: MWAWCell.cxx:787
MWAWCellContent()
constructor
Definition: MWAWCell.hxx:394
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const
get the numbering style
Definition: MWAWCell.cxx:76
a structure uses to define the format of a cell content
Definition: MWAWCell.hxx:60
MWAWBox2f const & bdBox() const
bdbox accessor
Definition: MWAWCell.hxx:182
Definition: MWAWCell.hxx:58
Definition: MWAWCell.hxx:56
bool hasBorders() const
return true if the cell has some border
Definition: MWAWCell.hxx:274
Definition: MWAWCell.hxx:58
void setProtected(bool fl)
sets the cell's protected flag
Definition: MWAWCell.hxx:246
Definition: MWAWCell.hxx:392
Definition: MWAWCell.hxx:124
bool isFontSet() const
returns true if the font has been set
Definition: MWAWCell.hxx:224
std::vector< MWAWBorder > m_bordersList
the cell border MWAWBorder::Pos
Definition: MWAWCell.hxx:349
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:558
VerticalAlignment m_vAlign
the vertical cell alignment : by default nothing
Definition: MWAWCell.hxx:342
MWAWEntry m_textEntry
the cell string
Definition: MWAWCell.hxx:440
std::string m_currencySymbol
the currency symbol ( default '$')
Definition: MWAWCell.hxx:101
MWAWVec2b m_positionRelative[2]
relative cell position ( if type==F_Cell or F_CellList )
Definition: MWAWCell.hxx:386
static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector)
convert a DTFormat in a propertyList
Definition: MWAWCell.cxx:157
Type m_type
the type
Definition: MWAWCell.hxx:376
void setValue(double value)
sets the double value
Definition: MWAWCell.hxx:409
std::string m_sheet
the sheet name (if not empty)
Definition: MWAWCell.hxx:388
Definition: MWAWCell.hxx:58
HorizontalAlignment hAlignment() const
returns the horizontal alignment
Definition: MWAWCell.hxx:252
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:774
virtual ~Format()
destructor
Definition: MWAWCell.hxx:67
bool m_protected
cell protected
Definition: MWAWCell.hxx:346
bool m_thousandHasSeparator
true if we must separate the thousand
Definition: MWAWCell.hxx:97
void setHAlignment(HorizontalAlignment align)
sets the horizontal alignment
Definition: MWAWCell.hxx:257
static std::string getColumnName(int col)
return the column name
Definition: MWAWCell.cxx:409
Definition: MWAWCell.hxx:58
ExtraLine extraLine() const
returns the extra lines
Definition: MWAWCell.hxx:308
HorizontalAlignment
the default horizontal alignment.
Definition: MWAWCell.hxx:118
bool m_parenthesesForNegative
true if we use parenthese to print negative number
Definition: MWAWCell.hxx:99
Definition: MWAWCell.hxx:392
a structure used to define a cell and its format
Definition: MWAWCell.hxx:52
the class to store a color
Definition: libmwaw_internal.hxx:176
MWAWColor backgroundColor() const
returns the background color
Definition: MWAWCell.hxx:293
Format m_format
the cell format
Definition: MWAWCell.hxx:334
double m_value
the cell value
Definition: MWAWCell.hxx:436
Definition: MWAWCell.hxx:127
std::vector< FormulaInstruction > m_formula
the formula list of instruction
Definition: MWAWCell.hxx:442
Definition: MWAWCell.hxx:392
small class use to define a sheet cell content
Definition: MWAWCell.hxx:357
FormatType
the different format of a cell's content
Definition: MWAWCell.hxx:56
MWAWVec2f m_bdSize
the cell bounding size : unit point
Definition: MWAWCell.hxx:331
MWAWBox2f m_bdBox
the cell bounding box (unit in point)
Definition: MWAWCell.hxx:329
virtual ~MWAWCell()
destructor
Definition: MWAWCell.hxx:136
Class to store font.
Definition: MWAWFont.hxx:43
a border
Definition: libmwaw_internal.hxx:308
bool hasText() const
returns true if the text is set
Definition: MWAWCell.hxx:420
friend std::ostream & operator<<(std::ostream &o, MWAWCellContent const &cell)
operator<<
Definition: MWAWCell.cxx:751
~MWAWCellContent()
destructor
Definition: MWAWCell.hxx:396
Definition: MWAWCell.hxx:58
void setBdSize(MWAWVec2f sz)
set the bdbox size(unit point)
Definition: MWAWCell.hxx:198
void setVAlignment(VerticalAlignment align)
sets the vertical alignment
Definition: MWAWCell.hxx:268
HorizontalAlignment m_hAlign
the cell alignment : by default nothing
Definition: MWAWCell.hxx:340
ExtraLine
an enum to defined potential internal line: E_Line1=TL to RB, E_Line2=BL to RT
Definition: MWAWCell.hxx:127
friend std::ostream & operator<<(std::ostream &o, Format const &format)
operator<<
Definition: MWAWCell.cxx:252
bool hasBasicFormat() const
returns true if this is a basic format style
Definition: MWAWCell.hxx:69
Definition: MWAWCell.hxx:124
MWAWVec2< bool > MWAWVec2b
MWAWVec2 of bool.
Definition: libmwaw_internal.hxx:772
friend std::ostream & operator<<(std::ostream &o, FormulaInstruction const &inst)
operator<<
Definition: MWAWCell.cxx:855
static bool double2Date(double val, int &Y, int &M, int &D)
conversion beetween double days since 1900 and a date, ie val=0 corresponds to 1/1/1900, val=365 to 1/1/1901, ...
Definition: MWAWCell.cxx:576
Definition: MWAWCell.hxx:119
std::string getValueType() const
returns a value type
Definition: MWAWCell.cxx:54
Format const & getFormat() const
returns the cell format
Definition: MWAWCell.hxx:213
Definition: MWAWCell.hxx:56
MWAWVec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: MWAWCell.hxx:327
FormatType m_format
the cell format : by default unknown
Definition: MWAWCell.hxx:85
void setExtraLine(ExtraLine extrLine, MWAWBorder const &type=MWAWBorder())
sets the extraline
Definition: MWAWCell.hxx:318
ExtraLine m_extraLine
extra line
Definition: MWAWCell.hxx:351
void resetBorders()
reset the border
Definition: MWAWCell.hxx:285
Type
Definition: MWAWCell.hxx:362
Definition: MWAWCell.hxx:127
MWAWVec2i m_position[2]
cell position ( if type==F_Cell or F_CellList )
Definition: MWAWCell.hxx:384
void setPosition(MWAWVec2i posi)
set the cell positions : 0,0 -> A1, 0,1 -> A2
Definition: MWAWCell.hxx:165
VerticalAlignment vAlignment() const
returns the vertical alignment
Definition: MWAWCell.hxx:263
MWAWVec2f const & bdSize() const
bdbox size accessor
Definition: MWAWCell.hxx:193
int m_numeratorDigits
the number of numerator digits
Definition: MWAWCell.hxx:93
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:434
Definition: MWAWCell.hxx:56
Definition: MWAWCell.hxx:124
void setNumSpannedCells(MWAWVec2i numSpanned)
sets the number of spanned cells : MWAWVec2i(1,1) means 1 cellule
Definition: MWAWCell.hxx:176
Definition: MWAWCell.hxx:119
int m_digits
the number of digits
Definition: MWAWCell.hxx:89
Definition: MWAWCell.hxx:58
MWAWColor m_backgroundColor
the backgroung color
Definition: MWAWCell.hxx:344
void addTo(librevenge::RVNGPropertyList &propList, shared_ptr< MWAWFontConverter > fontConverter) const
adds to the propList
Definition: MWAWCell.cxx:336
NumberType m_numberFormat
the numeric format
Definition: MWAWCell.hxx:87
bool m_fontSet
a flag to know if the font has been set
Definition: MWAWCell.hxx:338
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:436
bool hasExtraLine() const
returns true if we have some extra lines
Definition: MWAWCell.hxx:303
Definition: MWAWCell.hxx:392
static bool double2String(double val, MWAWCell::Format const &format, std::string &str)
conversion of the value in string knowing the cell format
Definition: MWAWCell.cxx:668
double m_longValue
value ( if type==F_Long )
Definition: MWAWCell.hxx:380
Definition: MWAWCell.hxx:127
CompareFormat()
constructor
Definition: MWAWCell.hxx:108
std::vector< MWAWBorder > const & borders() const
return the cell border: libmwaw::Left | ...
Definition: MWAWCell.hxx:279
MWAWBorder const & extraLineType() const
returns the extra line border
Definition: MWAWCell.hxx:313
bool m_valueSet
true if the value has been set
Definition: MWAWCell.hxx:438
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
bool empty() const
returns true if the cell has no content
Definition: MWAWCell.hxx:401
VerticalAlignment
the default vertical alignment.
Definition: MWAWCell.hxx:124
FormulaInstruction()
constructor
Definition: MWAWCell.hxx:364
NumberType
the different number format of a cell's content
Definition: MWAWCell.hxx:58
Definition: MWAWCell.hxx:118
std::string m_content
the content ( if type == F_Operator or type = F_Function or type==F_Text)
Definition: MWAWCell.hxx:378
int m_denominatorDigits
the number of denominator digits
Definition: MWAWCell.hxx:95
Definition: MWAWCell.hxx:124
std::string m_DTFormat
a date/time format ( using a subset of strftime format )
Definition: MWAWCell.hxx:103
void setBdBox(MWAWBox2f box)
set the bdbox (unit point)
Definition: MWAWCell.hxx:187
Definition: MWAWCell.hxx:127
bool isValueSet() const
returns true if the value has been setted
Definition: MWAWCell.hxx:415
Definition: MWAWCell.hxx:118
static bool date2Double(int Y, int M, int D, double &val)
conversion beetween date and double days since 1900 date
Definition: MWAWCell.cxx:626
bool operator()(Format const &c1, Format const &c2) const
comparaison function
Definition: MWAWCell.hxx:110
bool isProtected() const
returns true if the cell is protected
Definition: MWAWCell.hxx:241
int m_integerDigits
the number of main digits
Definition: MWAWCell.hxx:91
Definition: MWAWCell.hxx:118
Definition: MWAWCell.hxx:56
void setBorders(int wh, MWAWBorder const &border)
sets the cell border: wh=libmwaw::LeftBit|...
Definition: MWAWCell.cxx:456
bool isEmpty() const
returns true if the border is empty
Definition: libmwaw_internal.hxx:321

Generated on Fri Nov 27 2015 03:45:45 for libmwaw by doxygen 1.8.9.1