| 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 |
* Parser to spreadsheet's part of a RagTime document |
| 36 |
* |
| 37 |
*/ |
| 38 |
#ifndef RAGTIME_SPREADSHEET |
| 39 |
# define RAGTIME_SPREADSHEET |
| 40 |
|
| 41 |
#include <list> |
| 42 |
#include <string> |
| 43 |
#include <vector> |
| 44 |
|
| 45 |
#include "libmwaw_internal.hxx" |
| 46 |
|
| 47 |
#include "MWAWCell.hxx" |
| 48 |
#include "MWAWDebug.hxx" |
| 49 |
#include "MWAWEntry.hxx" |
| 50 |
#include "MWAWInputStream.hxx" |
| 51 |
|
| 52 |
#include "MWAWParser.hxx" |
| 53 |
|
| 54 |
namespace RagTimeSpreadsheetInternal |
| 55 |
{ |
| 56 |
struct ComplexBlock; |
| 57 |
|
| 58 |
struct Cell; |
| 59 |
struct Spreadsheet; |
| 60 |
|
| 61 |
struct State; |
| 62 |
} |
| 63 |
|
| 64 |
class RagTimeParser; |
| 65 |
|
| 66 |
/** \brief the main class to read the spreadsheet part of ragTime file |
| 67 |
* |
| 68 |
* |
| 69 |
* |
| 70 |
*/ |
| 71 |
class RagTimeSpreadsheet |
| 72 |
{ |
| 73 |
friend class RagTimeParser; |
| 74 |
public: |
| 75 |
//! constructor |
| 76 |
explicit RagTimeSpreadsheet(RagTimeParser &parser); |
| 77 |
//! destructor |
| 78 |
virtual ~RagTimeSpreadsheet(); |
| 79 |
|
| 80 |
/** returns the file version */ |
| 81 |
int version() const; |
| 82 |
|
| 83 |
protected: |
| 84 |
// generic resource ( used mainly by spreadsheet ) |
| 85 |
|
| 86 |
//! returns the ith date format or "" |
| 87 |
bool getDateTimeFormat(int dtId, std::string &dtFormat) const; |
| 88 |
//! try to read the numeric/date format table zone: FoTa |
| 89 |
bool readNumericFormat(MWAWEntry &entry); |
| 90 |
|
| 91 |
// specific spreadsheet resource |
| 92 |
|
| 93 |
//! try to read a SpXX resource |
| 94 |
bool readResource(MWAWEntry &entry); |
| 95 |
//! try to read the SpDo zone (a spreadsheet zone with id=0) |
| 96 |
bool readRsrcSpDo(MWAWEntry &entry); |
| 97 |
//! try to read the SpDI zone (a spreadsheet zone zone with id=0) |
| 98 |
bool readRsrcSpDI(MWAWEntry &entry); |
| 99 |
|
| 100 |
// |
| 101 |
|
| 102 |
//! try to read a spreadsheet zone: v3-... |
| 103 |
bool readSpreadsheet(MWAWEntry &entry); |
| 104 |
//! try to read a the last spreadsheet zone |
| 105 |
bool readSpreadsheetZone9(MWAWEntry const &entry, RagTimeSpreadsheetInternal::Spreadsheet &sheet); |
| 106 |
//! try to read a simple structured spreadsheet zone |
| 107 |
bool readSpreadsheetSimpleStructure(MWAWEntry const &entry, RagTimeSpreadsheetInternal::Spreadsheet &sheet); |
| 108 |
//! try to read a complex structured spreadsheet zone |
| 109 |
bool readSpreadsheetComplexStructure(MWAWEntry const &entry, RagTimeSpreadsheetInternal::Spreadsheet &sheet); |
| 110 |
|
| 111 |
//! try to read a spreadsheet cells content |
| 112 |
bool readSpreadsheetCellContent(RagTimeSpreadsheetInternal::Cell &cell, long endPos); |
| 113 |
//! try to read a spreadsheet cells dimension |
| 114 |
bool readSpreadsheetCellDimension(MWAWVec2i const &cellPos, long endPos, RagTimeSpreadsheetInternal::Spreadsheet &sheet); |
| 115 |
//! try to read a spreadsheet cell's format |
| 116 |
bool readSpreadsheetCellFormat(MWAWVec2i const &cellPos, long endPos, RagTimeSpreadsheetInternal::Cell &cell); |
| 117 |
|
| 118 |
//! try to read a list of position |
| 119 |
bool readPositionsList(MWAWEntry const &entry, std::vector<long> &posList, long &lastDataPos); |
| 120 |
//! try to read a complex bock header |
| 121 |
bool readBlockHeader(MWAWEntry const &entry, RagTimeSpreadsheetInternal::ComplexBlock &block); |
| 122 |
|
| 123 |
//! try to read spreadsheet zone ( a big zone):v2 |
| 124 |
bool readSpreadsheetV2(MWAWEntry &entry); |
| 125 |
//! try to read spreadsheet cells :v2 |
| 126 |
bool readSpreadsheetCellsV2(MWAWEntry &entry, RagTimeSpreadsheetInternal::Spreadsheet &sheet); |
| 127 |
//! try to read spreadsheet end zone (positions, ...) :v2 |
| 128 |
bool readSpreadsheetExtraV2(MWAWEntry &entry, RagTimeSpreadsheetInternal::Spreadsheet &sheet); |
| 129 |
|
| 130 |
//! send a spreadsheet corresponding to zId |
| 131 |
bool send(int zId, MWAWPosition const &pos); |
| 132 |
//! flush extra data |
| 133 |
void flushExtra(); |
| 134 |
|
| 135 |
// |
| 136 |
// low level |
| 137 |
// |
| 138 |
|
| 139 |
//! try to read a cell :v2 |
| 140 |
bool readSpreadsheetCellV2(RagTimeSpreadsheetInternal::Cell &cell, long endPos); |
| 141 |
//! try to read a formula |
| 142 |
bool readFormulaV2(MWAWVec2i const &cellPos, std::vector<MWAWCellContent::FormulaInstruction> &formula, long endPos, std::string &extra); |
| 143 |
//! try to read a formula: v3... |
| 144 |
bool readFormula(MWAWVec2i const &cellPos, std::vector<MWAWCellContent::FormulaInstruction> &formula, long endPos, std::string &extra); |
| 145 |
//! try to read a cell in a formula |
| 146 |
bool readCellInFormulaV2(MWAWVec2i const &pos, bool canBeList, MWAWCellContent::FormulaInstruction &instr, long endPos, std::string &extra); |
| 147 |
//! try to read a cell in a formula |
| 148 |
bool readCellInFormula(MWAWVec2i const &pos, bool canBeList, MWAWCellContent::FormulaInstruction &instr, long endPos, std::string &extra); |
| 149 |
//! send a spreadsheet to a listener |
| 150 |
bool send(RagTimeSpreadsheetInternal::Spreadsheet &sheet, MWAWSpreadsheetListenerPtr listener); |
| 151 |
|
| 152 |
private: |
| 153 |
RagTimeSpreadsheet(RagTimeSpreadsheet const &orig) = delete; |
| 154 |
RagTimeSpreadsheet &operator=(RagTimeSpreadsheet const &orig) = delete; |
| 155 |
|
| 156 |
protected: |
| 157 |
// |
| 158 |
// data |
| 159 |
// |
| 160 |
//! the parser state |
| 161 |
MWAWParserStatePtr m_parserState; |
| 162 |
|
| 163 |
//! the state |
| 164 |
std::shared_ptr<RagTimeSpreadsheetInternal::State> m_state; |
| 165 |
|
| 166 |
//! the main parser; |
| 167 |
RagTimeParser *m_mainParser; |
| 168 |
}; |
| 169 |
#endif |
| 170 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |