QuattroSpreadsheet.h Source File documentation

QuattroSpreadsheet.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2006, 2007 Andrew Ziem
11 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
12 * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
13 *
14 * For minor contributions see the git repository.
15 *
16 * Alternatively, the contents of this file may be used under the terms
17 * of the GNU Lesser General Public License Version 2.1 or later
18 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19 * applicable instead of those above.
20 */
21
22 #ifndef QUATTRO_SPREADSHEET_H
23 #define QUATTRO_SPREADSHEET_H
24
25 #include <ostream>
26 #include <map>
27 #include <vector>
28
29 #include <librevenge-stream/librevenge-stream.h>
30
31 #include "libwps_internal.h"
32
33 #include "WPSDebug.h"
34 #include "WKSContentListener.h"
35
36 namespace QuattroSpreadsheetInternal
37 {
38 class Cell;
39 class SpreadSheet;
40 struct State;
43 class CellReference
44 {
45 public:
47 CellReference()
48 : m_cells()
49 {
50 }
52 void addInstruction(WKSContentListener::FormulaInstruction const &instr)
53 {
54 if (!m_cells.empty() && instr.m_type!=instr.F_Operator && m_cells.back().m_type!=instr.F_Operator)
55 {
56 WKSContentListener::FormulaInstruction sep;
57 sep.m_type=sep.F_Operator;
58 sep.m_content=";";
59 m_cells.push_back(sep);
60 }
61 m_cells.push_back(instr);
62 }
64 bool empty() const
65 {
66 return m_cells.empty();
67 }
69 friend std::ostream &operator<<(std::ostream &o, CellReference const &ref);
71 std::vector<WKSContentListener::FormulaInstruction> m_cells;
72 };
73 }
74
75 class QuattroParser;
76
81 class QuattroSpreadsheet
82 {
83 public:
84 friend class QuattroParser;
85
87 explicit QuattroSpreadsheet(QuattroParser &parser);
89 ~QuattroSpreadsheet();
91 void setListener(WKSContentListenerPtr &listen)
92 {
93 m_listener = listen;
94 }
96 void cleanState();
98 void updateState();
99
100 protected:
102 int version() const;
103
105 int getNumSpreadsheets() const;
107 librevenge::RVNGString getSheetName(int id) const;
109 void sendSpreadsheet(int sheetId, std::vector<Vec2i> const &listGraphicCells);
111 Vec2f getPosition(int sheetId, Vec2i const &cell) const;
113 void sendCellContent(QuattroSpreadsheetInternal::Cell const &cell, int sheetId);
114
116 void addDLLIdName(int id, librevenge::RVNGString const &name, bool func1);
118 void addUserFormat(int id, librevenge::RVNGString const &name);
119
120 //
121 // low level
122 //
124
126 bool readCell(std::shared_ptr<WPSStream> stream);
128 bool readSheetSize(std::shared_ptr<WPSStream> stream);
130 bool readColumnRowDefaultSize(std::shared_ptr<WPSStream> stream);
132 bool readColumnSize(std::shared_ptr<WPSStream> stream);
134 bool readRowSize(std::shared_ptr<WPSStream> stream);
136 bool readRowRangeSize(std::shared_ptr<WPSStream> stream);
137
139 bool readBeginEndSheet(std::shared_ptr<WPSStream> stream, int &sheetId);
141 bool readSheetName(std::shared_ptr<WPSStream> stream);
143 bool readCellStyle(std::shared_ptr<WPSStream> stream);
144
146 bool readViewInfo(std::shared_ptr<WPSStream> stream);
147
148 /* reads a cell */
149 bool readCell(std::shared_ptr<WPSStream> stream, Vec2i actPos, WKSContentListener::FormulaInstruction &instr, int sheetId, librevenge::RVNGString const &fName) const;
150 /* reads a formula */
151 bool readFormula(std::shared_ptr<WPSStream> stream, long endPos, Vec2i const &pos, int sheetId,
152 std::vector<WKSContentListener::FormulaInstruction> &formula, std::string &error);
154 void updateCellWithUserFormat(QuattroSpreadsheetInternal::Cell &cell, librevenge::RVNGString const &format);
156 bool readCellReference(std::shared_ptr<WPSStream> stream, long endPos,
157 QuattroSpreadsheetInternal::CellReference &ref,
158 Vec2i const &pos=Vec2i(0,0), int sheetId=0) const;
159
160 private:
161 QuattroSpreadsheet(QuattroSpreadsheet const &orig) = delete;
162 QuattroSpreadsheet &operator=(QuattroSpreadsheet const &orig) = delete;
163 std::shared_ptr<WKSContentListener> m_listener;
164 QuattroParser &m_mainParser;
167 std::shared_ptr<QuattroSpreadsheetInternal::State> m_state;
168 };
169
170 #endif /* WPS4_H */
171 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
QuattroSpreadsheet::updateCellWithUserFormat
void updateCellWithUserFormat(QuattroSpreadsheetInternal::Cell &cell, librevenge::RVNGString const &format)
try to update the cell&#39;s format using the user format
Definition: QuattroSpreadsheet.cpp:2126
QuattroSpreadsheet::m_state
std::shared_ptr< QuattroSpreadsheetInternal::State > m_state
the internal state
Definition: QuattroSpreadsheet.h:167
QuattroSpreadsheet::getSheetName
librevenge::RVNGString getSheetName(int id) const
returns the name of the id&#39;s spreadsheet
Definition: QuattroSpreadsheet.cpp:573
QuattroSpreadsheet::cleanState
void cleanState()
clean internal state
Definition: QuattroSpreadsheet.cpp:548
QuattroSpreadsheet::readFormula
bool readFormula(std::shared_ptr< WPSStream > stream, long endPos, Vec2i const &pos, int sheetId, std::vector< WKSContentListener::FormulaInstruction > &formula, std::string &error)
Definition: QuattroSpreadsheet.cpp:1674
QuattroSpreadsheet::readSheetName
bool readSheetName(std::shared_ptr< WPSStream > stream)
reads sheet name: zone cc
Definition: QuattroSpreadsheet.cpp:1346
QuattroSpreadsheet::setListener
void setListener(WKSContentListenerPtr &listen)
sets the listener
Definition: QuattroSpreadsheet.h:91
QuattroSpreadsheet::addDLLIdName
void addDLLIdName(int id, librevenge::RVNGString const &name, bool func1)
add a dll&#39;s correspondance between an id and a name
Definition: QuattroSpreadsheet.cpp:589
WKSContentListener::FormulaInstruction::m_type
What m_type
the type
Definition: WKSContentListener.h:77
QuattroSpreadsheet::~QuattroSpreadsheet
~QuattroSpreadsheet()
destructor
Definition: QuattroSpreadsheet.cpp:544
QuattroSpreadsheetInternal::CellReference::addInstruction
void addInstruction(WKSContentListener::FormulaInstruction const &instr)
add an instruction
Definition: QuattroSpreadsheet.h:52
QuattroSpreadsheet::operator=
QuattroSpreadsheet & operator=(QuattroSpreadsheet const &orig)=delete
WKSContentListener.h
WKSContentListener::FormulaInstruction::F_Operator
Definition: WKSContentListener.h:59
WKSContentListener::FormulaInstruction::m_content
std::string m_content
the content ( if type == F_Operator or type = F_Function or type==F_Text)
Definition: WKSContentListener.h:79
QuattroSpreadsheetInternal::CellReference
small class use to store Quattro Pro cell reference
Definition: QuattroSpreadsheet.h:43
QuattroSpreadsheet::m_mainParser
QuattroParser & m_mainParser
the listener (if set)
Definition: QuattroSpreadsheet.h:165
QuattroSpreadsheetInternal::CellReference::empty
bool empty() const
return true if we have not read any reference
Definition: QuattroSpreadsheet.h:64
QuattroSpreadsheetInternal::CellReference::CellReference
CellReference()
constructor
Definition: QuattroSpreadsheet.h:47
QuattroSpreadsheet::readViewInfo
bool readViewInfo(std::shared_ptr< WPSStream > stream)
reads a view info: zone 197/198
Definition: QuattroSpreadsheet.cpp:1387
libwps_internal.h
QuattroSpreadsheet::readColumnSize
bool readColumnSize(std::shared_ptr< WPSStream > stream)
reads the column size: zone d8,d9
Definition: QuattroSpreadsheet.cpp:1143
libwps_tools_win::Language::name
std::string name(long id)
returns the name given Windows© id
Definition: libwps_tools_win.cpp:7299
QuattroSpreadsheet::m_listener
std::shared_ptr< WKSContentListener > m_listener
Definition: QuattroSpreadsheet.h:163
QuattroSpreadsheet::sendSpreadsheet
void sendSpreadsheet(int sheetId, std::vector< Vec2i > const &listGraphicCells)
send the sId&#39;th spreadsheet
Definition: QuattroSpreadsheet.cpp:2037
QuattroSpreadsheetInternal::CellReference::m_cells
std::vector< WKSContentListener::FormulaInstruction > m_cells
the list of instruction coding each cell&#39;s block
Definition: QuattroSpreadsheet.h:71
QuattroParser
This class parses Quattro Pro spreadsheet: .wq1 and wq2.
Definition: Quattro.h:53
QuattroSpreadsheet::readCell
bool readCell(std::shared_ptr< WPSStream > stream)
reads a cell content data: zone 0xc-0x10 or 33
Definition: QuattroSpreadsheet.cpp:645
QuattroSpreadsheet
This class parses Quattro Pro spreadsheet file.
Definition: QuattroSpreadsheet.h:81
QuattroSpreadsheet::sendCellContent
void sendCellContent(QuattroSpreadsheetInternal::Cell const &cell, int sheetId)
send the cell data
Definition: QuattroSpreadsheet.cpp:2351
QuattroSpreadsheet::readBeginEndSheet
bool readBeginEndSheet(std::shared_ptr< WPSStream > stream, int &sheetId)
read the begin/end of a sheet zone: zone ca and cb
Definition: QuattroSpreadsheet.cpp:1299
QuattroSpreadsheet::readRowRangeSize
bool readRowRangeSize(std::shared_ptr< WPSStream > stream)
reads the row size: zone 105,106
Definition: QuattroSpreadsheet.cpp:1246
QuattroSpreadsheet::readCellStyle
bool readCellStyle(std::shared_ptr< WPSStream > stream)
reads a cell attribute: zone 0xce
Definition: QuattroSpreadsheet.cpp:827
Vec2i
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:702
QuattroSpreadsheet::readSheetSize
bool readSheetSize(std::shared_ptr< WPSStream > stream)
reads sheet size: zone 06
Definition: QuattroSpreadsheet.cpp:1062
QuattroSpreadsheet::readColumnRowDefaultSize
bool readColumnRowDefaultSize(std::shared_ptr< WPSStream > stream)
reads the sheet column/row default size: zone d2-d5
Definition: QuattroSpreadsheet.cpp:1103
QuattroSpreadsheet::addUserFormat
void addUserFormat(int id, librevenge::RVNGString const &name)
add a user format&#39;s correspondance between an id and a name
Definition: QuattroSpreadsheet.cpp:624
QuattroSpreadsheet::readRowSize
bool readRowSize(std::shared_ptr< WPSStream > stream)
reads the row size: zone d6,d7
Definition: QuattroSpreadsheet.cpp:1197
QuattroSpreadsheetInternal::Cell
a cellule of a Quattro spreadsheet
Definition: QuattroSpreadsheet.cpp:103
WKSContentListenerPtr
std::shared_ptr< WKSContentListener > WKSContentListenerPtr
shared pointer to WKSContentListener
Definition: libwps_internal.h:114
QuattroSpreadsheet::readCellReference
bool readCellReference(std::shared_ptr< WPSStream > stream, long endPos, QuattroSpreadsheetInternal::CellReference &ref, Vec2i const &pos=Vec2i(0, 0), int sheetId=0) const
try to read a cell reference
Definition: QuattroSpreadsheet.cpp:1586
Vec2< float >
QuattroSpreadsheet::QuattroSpreadsheet
QuattroSpreadsheet(QuattroParser &parser)
constructor
Definition: QuattroSpreadsheet.cpp:537
WKSContentListener::FormulaInstruction
small class use to define a formula instruction
Definition: WKSContentListener.h:57
QuattroSpreadsheet::version
int version() const
return the file version
Definition: QuattroSpreadsheet.cpp:557
QuattroSpreadsheet::updateState
void updateState()
update the state (need to be called before sending data)
Definition: QuattroSpreadsheet.cpp:553
WPSDebug.h
QuattroSpreadsheetInternal::CellReference::operator<<
friend std::ostream & operator<<(std::ostream &o, CellReference const &ref)
friend operator<<
Definition: QuattroSpreadsheet.cpp:2444
QuattroSpreadsheet::getPosition
Vec2f getPosition(int sheetId, Vec2i const &cell) const
returns the beginning position of a cell
Definition: QuattroSpreadsheet.cpp:578
QuattroSpreadsheet::getNumSpreadsheets
int getNumSpreadsheets() const
returns the number of spreadsheet
Definition: QuattroSpreadsheet.cpp:564
QuattroSpreadsheetInternal
Definition: Quattro.h:45