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 
34 /* Define some classes used to store a Cell
35  */
36 
37 #ifndef MWAW_CELL_H
38 # define MWAW_CELL_H
39 
40 #include <string>
41 #include <vector>
42 
43 #include "libmwaw_internal.hxx"
44 
45 class WPXPropertyList;
46 
49 {
50 public:
56  };
57 
61 
64 
65  /* subformat:
66  NUMBER DATE TIME TEXT
67  0 : default default default default
68  1 : decimal 3/2/00 10:03:00 AM -------
69  2 : exponential 3 Feb, 2000 10:03 AM -------
70  3 : percent 3, Feb 10:03:00 -------
71  4 : money Feb, 2000 10:03 -------
72  5 : thousand Thu, 3 Feb, 2000 ------- -------
73  6 : percent/thou 3 February 2000 ------- -------
74  7 : money/thou Thursday, February 3, 2000 ------- -------
75 
76  */
80  m_backgroundColor(MWAWColor::white()), m_protected(false) { }
81 
82  virtual ~MWAWCellFormat() {}
83 
85  Format format() const {
86  return m_format;
87  }
89  int subformat() const {
90  return m_subFormat;
91  }
93  void setFormat(Format form, int subform=0) {
94  m_format = form;
95  m_subFormat = subform;
96  }
98  void setSubformat(int subFormat) {
99  m_subFormat = subFormat;
100  }
101 
103  int digits() const {
104  return m_digits;
105  }
107  void setDigits(int newDigit) {
108  m_digits = newDigit;
109  }
110 
112  bool isProtected() const {
113  return m_protected;
114  }
115 
117  void setProtected(bool fl) {
118  m_protected = fl;
119  }
120 
123  return m_hAlign;
124  }
127  m_hAlign = align;
128  }
129 
132  return m_vAlign;
133  }
136  m_vAlign = align;
137  }
138 
140  bool hasBorders() const {
141  return m_bordersList.size() != 0;
142  }
144  std::vector<MWAWBorder> const &borders() const {
145  return m_bordersList;
146  }
147 
149  void resetBorders() {
150  m_bordersList.resize(0);
151  }
153  void setBorders(int wh, MWAWBorder const &border);
154 
157  return m_backgroundColor;
158  }
161  m_backgroundColor = color;
162  }
163 
165  int compare(MWAWCellFormat const &cell) const;
166 
168  friend std::ostream &operator<<(std::ostream &o, MWAWCellFormat const &cell);
169 
170 protected:
176  int m_digits;
182  std::vector<MWAWBorder> m_bordersList;
187 };
188 
191 {
192 public:
195 
198  m_textValue(""), m_textValueSet(false), m_formulaValue("") { }
199  virtual ~MWAWCellContent() {}
200 
202  Content content() const {
203  return m_contentType;
204  }
206  void setContent(Content type) {
207  m_contentType = type;
208  }
209 
211  void setValue(double val) {
212  m_value = val;
213  m_valueSet = true;
214  }
216  double value() const {
217  return m_value;
218  }
220  bool isValueSet() const {
221  return m_valueSet;
222  }
223 
225  void setText(std::string const &val) {
226  m_textValue = val;
227  m_textValueSet = true;
228  }
230  std::string const &text() const {
231  return m_textValue;
232  }
234  bool hasText() const {
235  return m_textValue.size() != 0;
236  }
238  bool isTextSet() const {
239  return m_textValueSet;
240  }
241 
243  void setFormula(std::string const &val) {
244  m_formulaValue = val;
245  }
247  std::string const &formula() const {
248  return m_formulaValue;
249  }
250 
252  bool empty() const {
253  if (m_contentType == C_NUMBER) return false;
254  if (m_contentType == C_TEXT && m_textValue.size()) return false;
255  if (m_contentType == C_FORMULA && (m_formulaValue.size() || isValueSet())) return false;
256  return true;
257  }
258 
266  bool getDataCellProperty(MWAWCellFormat::Format format, WPXPropertyList &property,
267  std::string &text) const;
268 
270  static bool double2Date(double val, int &Y, int &M, int &D);
272  static bool double2Time(double val, int &H, int &M, int &S);
273 
275  friend std::ostream &operator<<(std::ostream &o, MWAWCellContent const &cell);
276 
277 protected:
280 
282  double m_value;
285 
287  std::string m_textValue;
291  std::string m_formulaValue;
292 };
293 
295 class MWAWCell : public MWAWCellFormat
296 {
297 public:
300 
303  return m_position;
304  }
306  Vec2i const &position() const {
307  return m_position;
308  }
310  void setPosition(Vec2i posi) {
311  m_position = posi;
312  }
313 
315  Vec2i const &numSpannedCells() const {
316  return m_numberCellSpanned;
317  }
319  void setNumSpannedCells(Vec2i numSpanned) {
320  m_numberCellSpanned=numSpanned;
321  }
322 
324  friend std::ostream &operator<<(std::ostream &o, MWAWCell const &cell);
325 
327  static std::string getCellName(Vec2i const &pos, Vec2b const &absolute);
328 
330  static std::string getColumnName(int col);
331 
332 protected:
337 };
338 
339 #endif
340 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Wed Jul 10 2013 18:19:41 for libmwaw by doxygen 1.8.4