Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libstaroffice/src/lib/STOFFCell.hxx
Line
Count
Source
1
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3
/* libstaroffice
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
/** \file STOFFCell.hxx
35
 * Defines STOFFCell (cell content and format)
36
 */
37
38
#ifndef STOFF_CELL_H
39
#  define STOFF_CELL_H
40
41
#include <string>
42
#include <vector>
43
44
#include "libstaroffice_internal.hxx"
45
46
#include "STOFFEntry.hxx"
47
#include "STOFFFont.hxx"
48
#include "STOFFCellStyle.hxx"
49
50
class STOFFTable;
51
52
/** a structure used to define a cell and its format */
53
class STOFFCell
54
{
55
public:
56
  /** the different format of a cell's content */
57
  enum FormatType { F_TEXT, F_BOOLEAN, F_NUMBER, F_DATE, F_TIME, F_DATETIME, F_UNKNOWN };
58
  /** the different number format of a cell's content */
59
  enum NumberType { F_NUMBER_CURRENCY, F_NUMBER_DECIMAL, F_NUMBER_FRACTION, F_NUMBER_GENERIC, F_NUMBER_SCIENTIFIC, F_NUMBER_PERCENT, F_NUMBER_UNKNOWN };
60
  /** a structure uses to define the format of a cell content */
61
  struct Format {
62
    //! constructor
63
    Format()
64
696k
      : m_format(F_UNKNOWN)
65
696k
      , m_numberFormat(F_NUMBER_UNKNOWN)
66
696k
    {
67
696k
    }
68
    //! destructor
69
    virtual ~Format();
70
    //! returns true if this is a basic format style
71
    bool hasBasicFormat() const
72
735k
    {
73
735k
      return m_format==F_TEXT || m_format==F_UNKNOWN;
74
735k
    }
75
    //! returns a value type
76
    std::string getValueType() const;
77
    //! convert a DTFormat in a propertyList
78
    static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
79
    //! operator<<
80
    friend std::ostream &operator<<(std::ostream &o, Format const &format);
81
82
    //! the cell format : by default unknown
83
    FormatType m_format;
84
    //! the numeric format
85
    NumberType m_numberFormat;
86
  };
87
  //! constructor
88
  STOFFCell()
89
696k
    : m_position(0,0)
90
696k
    , m_bdBox()
91
696k
    , m_bdSize()
92
696k
    , m_format()
93
696k
    , m_font()
94
696k
    , m_cellStyle()
95
696k
    , m_numberingStyle() { }
96
97
  //! destructor
98
696k
  virtual ~STOFFCell() {}
99
100
  /** adds to the propList*/
101
  void addTo(librevenge::RVNGPropertyList &propList) const;
102
103
  //! operator<<
104
  friend std::ostream &operator<<(std::ostream &o, STOFFCell const &cell);
105
106
  // interface with STOFFTable:
107
108
  /** function called when a cell is send by STOFFTable to send a cell to a
109
      listener.
110
111
      By default: calls openTableCell(*this), sendContent and then closeTableCell() */
112
  virtual bool send(STOFFListenerPtr listener, STOFFTable &table);
113
  /** function called when the content of a cell must be send to the listener,
114
      ie. when STOFFTable::sendTable or STOFFTable::sendAsText is called.
115
116
      \note default behavior: does nothing and prints an error in debug mode.*/
117
  virtual bool sendContent(STOFFListenerPtr listener, STOFFTable &table);
118
119
  // position
120
121
  //! position  accessor
122
  STOFFVec2i const &position() const
123
1.52M
  {
124
1.52M
    return m_position;
125
1.52M
  }
126
  //! set the cell positions :  0,0 -> A1, 0,1 -> A2
127
  void setPosition(STOFFVec2i posi)
128
951k
  {
129
951k
    m_position = posi;
130
951k
  }
131
132
  //! bdbox  accessor
133
  STOFFBox2f const &bdBox() const
134
0
  {
135
0
    return m_bdBox;
136
0
  }
137
  //! set the bdbox (unit point)
138
  void setBdBox(STOFFBox2f box)
139
0
  {
140
0
    m_bdBox = box;
141
0
  }
142
143
  //! bdbox size accessor
144
  STOFFVec2f const &bdSize() const
145
0
  {
146
0
    return m_bdSize;
147
0
  }
148
  //! set the bdbox size(unit point)
149
  void setBdSize(STOFFVec2f sz)
150
0
  {
151
0
    m_bdSize = sz;
152
0
  }
153
154
  //! return the name of a cell (given row and column) : 0,0 -> A1, 0,1 -> A2
155
  static std::string getCellName(STOFFVec2i const &pos, STOFFVec2b const &absolute);
156
157
  //! return the column name
158
  static std::string getColumnName(int col);
159
160
  // format
161
162
  //! returns the cell format
163
  Format const &getFormat() const
164
1.85M
  {
165
1.85M
    return m_format;
166
1.85M
  }
167
  //! set the cell format
168
  void setFormat(Format const &format)
169
768k
  {
170
768k
    m_format=format;
171
768k
  }
172
173
  //! returns the font
174
  STOFFFont const &getFont() const
175
0
  {
176
0
    return m_font;
177
0
  }
178
  //! set the font
179
  void setFont(STOFFFont const &font)
180
552k
  {
181
552k
    m_font=font;
182
552k
  }
183
184
  //! returns the cell style
185
  STOFFCellStyle const &getCellStyle() const
186
0
  {
187
0
    return m_cellStyle;
188
0
  }
189
  //! returns the cell style
190
  STOFFCellStyle &getCellStyle()
191
579k
  {
192
579k
    return m_cellStyle;
193
579k
  }
194
  //! set the cell style
195
  void setCellStyle(STOFFCellStyle const &cellStyle)
196
579k
  {
197
579k
    m_cellStyle=cellStyle;
198
579k
  }
199
200
  //! returns the numbering style
201
  librevenge::RVNGPropertyList const &getNumberingStyle() const
202
454k
  {
203
454k
    return m_numberingStyle;
204
454k
  }
205
  //! returns the numbering style
206
  librevenge::RVNGPropertyList &getNumberingStyle()
207
632k
  {
208
632k
    return m_numberingStyle;
209
632k
  }
210
  //! set the numbering style
211
  void setNumberingStyle(librevenge::RVNGPropertyList const &numberStyle)
212
0
  {
213
0
    m_numberingStyle=numberStyle;
214
0
  }
215
protected:
216
  //! the cell row and column : 0,0 -> A1, 0,1 -> A2
217
  STOFFVec2i m_position;
218
  /** the cell bounding box (unit in point)*/
219
  STOFFBox2f m_bdBox;
220
  /** the cell bounding size : unit point */
221
  STOFFVec2f m_bdSize;
222
223
  //! the cell format
224
  Format m_format;
225
  //! the cell font
226
  STOFFFont m_font;
227
  //! the cell cell style
228
  STOFFCellStyle m_cellStyle;
229
  //! the numbering style
230
  librevenge::RVNGPropertyList m_numberingStyle;
231
};
232
233
//! small class use to define a sheet cell content
234
class STOFFCellContent
235
{
236
public:
237
  //! small class use to define a formula instruction
238
  struct FormulaInstruction {
239
    enum Type { F_None, F_Operator, F_Function, F_Cell, F_CellList, F_Index, F_Long, F_Double, F_Text };
240
    //! constructor
241
495k
    FormulaInstruction() : m_type(F_None), m_content(""), m_longValue(0), m_doubleValue(0), m_sheet(""),
242
495k
      m_sheetId(-1), m_sheetIdRelative(false), m_extra("")
243
495k
    {
244
1.48M
      for (int i=0; i<2; ++i) {
245
991k
        m_position[i]=STOFFVec2i(0,0);
246
991k
        m_positionRelative[i]=STOFFVec2b(false,false);
247
991k
      }
248
495k
    }
249
    /** returns a proplist corresponding to a instruction */
250
    librevenge::RVNGPropertyList getPropertyList() const;
251
    //! operator<<
252
    friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
253
    //! the type
254
    Type m_type;
255
    //! the content ( if type == F_Operator or type = F_Function or type==F_Text)
256
    librevenge::RVNGString m_content;
257
    //! value ( if type==F_Long )
258
    long m_longValue;
259
    //! value ( if type==F_Double )
260
    double m_doubleValue;
261
    //! cell position ( if type==F_Cell or F_CellList )
262
    STOFFVec2i m_position[2];
263
    //! relative cell position ( if type==F_Cell or F_CellList )
264
    STOFFVec2b m_positionRelative[2];
265
    //! the sheet name (if not empty)
266
    librevenge::RVNGString m_sheet;
267
    //! the sheet id (if set)
268
    int m_sheetId;
269
    //! the sheet id relative flag
270
    bool m_sheetIdRelative;
271
    //! extra data
272
    std::string m_extra;
273
  };
274
275
  /** the different types of cell's field */
276
  enum Type { C_NONE, C_TEXT, C_TEXT_BASIC, C_NUMBER, C_FORMULA, C_UNKNOWN };
277
  /// constructor
278
724k
  STOFFCellContent() : m_contentType(C_UNKNOWN), m_value(0.0), m_valueSet(false), m_text(), m_formula() { }
279
  /// destructor
280
724k
  ~STOFFCellContent() {}
281
  //! operator<<
282
  friend std::ostream &operator<<(std::ostream &o, STOFFCellContent const &cell);
283
284
  //! returns true if the cell has no content
285
  bool empty() const
286
0
  {
287
0
    if (m_contentType == C_NUMBER || m_contentType == C_TEXT) return false;
288
0
    if (m_contentType == C_TEXT_BASIC && !m_text.empty()) return false;
289
0
    if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
290
0
    return true;
291
0
  }
292
  //! sets the double value
293
  void setValue(double value)
294
361k
  {
295
361k
    m_value = value;
296
361k
    m_valueSet = true;
297
361k
  }
298
  //! returns true if the value has been setted
299
  bool isValueSet() const
300
1.09M
  {
301
1.09M
    return m_valueSet;
302
1.09M
  }
303
  //! returns true if the text is set
304
  bool hasText() const
305
0
  {
306
0
    return m_contentType == C_TEXT || !m_text.empty();
307
0
  }
308
  /** conversion beetween double days since 1900 and a date, ie val=0
309
      corresponds to 1/1/1900, val=365 to 1/1/1901, ... */
310
  static bool double2Date(double val, int &Y, int &M, int &D);
311
  /** conversion beetween double: second since 0:00 and time */
312
  static bool double2Time(double val, int &H, int &M, int &S);
313
  /** conversion beetween date and double days since 1900 date */
314
  static bool date2Double(int Y, int M, int D, double &val);
315
  //! the content type ( by default unknown )
316
  Type m_contentType;
317
  //! the cell value
318
  double m_value;
319
  //! true if the value has been set
320
  bool m_valueSet;
321
  //! the text value (for C_TEXT_BASIC)
322
  std::vector<uint32_t> m_text;
323
  //! the formula list of instruction
324
  std::vector<FormulaInstruction> m_formula;
325
};
326
327
#endif
328
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: