Debian Codegraph @

src/lib/ClarisWksDbaseContent.hxx

raw
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 ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
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 /*
35 * The main database content used by Claris Works parser to store spreedsheet/Databese
36 *
37 */
38 #ifndef CLARIS_WKS_DBASE_CONTENT
39 # define CLARIS_WKS_DBASE_CONTENT
40
41 #include <iostream>
42 #include <map>
43 #include <set>
44 #include <vector>
45
46 #include "libmwaw_internal.hxx"
47
48 #include "MWAWCell.hxx"
49 #include "MWAWEntry.hxx"
50 #include "MWAWFont.hxx"
51
52 #include "ClarisWksStyleManager.hxx"
53
54 class ClarisWksDocument;
55
56 //! small structure used to parse main content of a spreadsheet/database zone
57 class ClarisWksDbaseContent
58 {
59 public:
60 struct Record;
61
62 //! constructor
63 ClarisWksDbaseContent(ClarisWksDocument &document, bool spreadsheet);
64 //! destructor
65 ~ClarisWksDbaseContent();
66 //! try to read the record structure
67 bool readContent();
68 //! read to read a formula
69 bool readFormula(MWAWVec2i const &cPos, long endPos,
70 std::vector<MWAWCellContent::FormulaInstruction> &formula, std::string &error);
71
72 //! returns the dimension of the read data
73 bool getExtrema(MWAWVec2i &min, MWAWVec2i &max) const;
74 //! returns the list of filled record/row
75 bool getRecordList(std::vector<int> &list) const;
76 //! returns the list of filled columns
77 bool getColumnList(int row, std::vector<int> &list) const;
78
79 //! retrieves the cell data
80 bool get(MWAWVec2i const &pos, Record &data) const;
81 //! try to send a cell content to the listener
82 bool send(MWAWVec2i const &pos);
83 //! set the field format ( for database )
84 void setDatabaseFormats(std::vector<ClarisWksStyleManager::CellFormat> const &format);
85 /** struct which stores a record in ClarisWksDbaseContent */
86 struct Record {
87 //! contructor
88 Record()
89 : m_style(-1)
90 , m_format()
91 , m_hAlign(MWAWCell::HALIGN_DEFAULT)
92 , m_fileFormat(0)
93 , m_content()
94 , m_valueType(MWAWCellContent::C_UNKNOWN)
95 , m_hasNaNValue(false)
96 , m_backgroundColor(MWAWColor::white())
97 , m_font(3,9)
98 , m_borders(0)
99 , m_posToFontMap()
100 {
101 }
102 //! update the formula cell (removing delta to each position)
103 void updateFormulaCells(MWAWVec2i const &removeDelta);
104 //! the style if known
105 int m_style;
106 //! the format
107 MWAWCell::Format m_format;
108 //! the cell alignment : by default nothing
109 MWAWCell::HorizontalAlignment m_hAlign;
110 //! the format ( in a v1-3 spreadsheet)
111 int m_fileFormat;
112 //! the content
113 MWAWCellContent m_content;
114 //! the type of the content value ( original or result of a formula )
115 MWAWCellContent::Type m_valueType;
116 //! a flag to know if a double result is nan or not
117 bool m_hasNaNValue;
118 //! the background color
119 MWAWColor m_backgroundColor;
120 //! the font ( in v1-3 spreadsheet)
121 MWAWFont m_font;
122 //! the border in v1-3 spreadsheet
123 int m_borders;
124 //! map id to font ( in database)
125 std::map<int, MWAWFont> m_posToFontMap;
126 };
127 protected:
128 /** struct which stores a column in ClarisWksDbaseContent */
129 struct Column {
130 //! constructor
131 Column()
132 : m_idRecordMap()
133 {
134 }
135 //! a map line (or record id) to record
136 std::map<int,Record> m_idRecordMap;
137 };
138
139 //! try to read the columns list structure(CTAB)
140 bool readColumnList();
141 //! try to read the column structure(COLM): a list of chnk
142 bool readColumn(int c);
143 //! try to read a list of records(CHNK)
144 bool readRecordList(MWAWVec2i const &where, Column &col);
145 //! try to read a spreadsheet record
146 bool readRecordSS(MWAWVec2i const &where, long pos, Record &record);
147 //! try to read a spreadsheet record(v1-v3)
148 bool readRecordSSV1(MWAWVec2i const &where, long pos, Record &record);
149 //! try to read a database record
150 bool readRecordDB(MWAWVec2i const &where, long pos, Record &record);
151
152 //! send a double with a corresponding cell format
153 void send(double val, bool isNotaNumber, ClarisWksStyleManager::CellFormat const &format);
154
155 //
156 // low level
157 //
158
159 /** reads a cell */
160 bool readCellInFormula(MWAWVec2i const &pos, MWAWCellContent::FormulaInstruction &instr);
161 /** try to read a string */
162 bool readString(long endPos, std::string &res);
163 /** try to read a number */
164 bool readNumber(long endPos, double &res, bool &isNan);
165 //! update the position set
166 void updateCellPositionsSet() const;
167
168 //! the file version
169 int m_version;
170 //! a bool to know if this is a spreadsheet or a database
171 bool m_isSpreadsheet;
172
173 //! the document
174 ClarisWksDocument &m_document;
175 //! the parser state
176 MWAWParserStatePtr m_parserState;
177
178 //! a map col id to column
179 std::map<int, Column> m_idColumnMap;
180 //! a set of cell position (sorted by row)
181 mutable std::set<MWAWVec2i> m_positionSet;
182 //! the databse format
183 std::vector<ClarisWksStyleManager::CellFormat> m_dbFormatList;
184 };
185 #endif
186 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
187
188