WKSContentListener.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) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
12 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
13 * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
14 *
15 * For minor contributions see the git repository.
16 *
17 * Alternatively, the contents of this file may be used under the terms
18 * of the GNU Lesser General Public License Version 2.1 or later
19 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
20 * applicable instead of those above.
21 *
22 * For further information visit http://libwps.sourceforge.net
23 */
24
25#ifndef WKSCONTENTLISTENER_H
26#define WKSCONTENTLISTENER_H
27
28#include <vector>
29
30#include <librevenge/librevenge.h>
31
32#include "libwps_internal.h"
33
34#include "WPSEntry.h"
35#include "WPSGraphicStyle.h"
36
37#include "WPSListener.h"
38
39class WPSCellFormat;
40class WKSChart;
41struct WPSColumnFormat;
42class WPSGraphicShape;
43class WPSGraphicStyle;
44class WPSList;
45class WPSPageSpan;
46struct WPSParagraph;
47struct WPSRowFormat;
48struct WPSTabStop;
49
52
53class WKSContentListener final : public WPSListener
54{
55public:
58 {
62 : m_type(F_Text)
63 , m_content()
64 , m_longValue(0)
65 , m_doubleValue(0)
66 , m_fileName()
67 {
68 for (auto &pos : m_position) pos=Vec2i(0,0);
69 for (auto &pos : m_positionRelative) pos=Vec2b(false,false);
70 for (auto &id : m_sheetId) id=-1;
71 }
72
73 librevenge::RVNGPropertyList getPropertyList() const;
75 friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
76
78 static void enclose(std::vector<FormulaInstruction> &formula, bool force);
80 static void add(std::vector<FormulaInstruction> &formula, int n);
81
85 std::string m_content;
89 long double m_doubleValue;
95 librevenge::RVNGString m_sheetName[2];
100 int m_sheetId[2];
102 librevenge::RVNGString m_fileName;
103 };
104
106 {
112 , m_value(0.0)
113 , m_valueSet(false)
114 , m_textEntry()
115 , m_formula() { }
116 CellContent(CellContent const &)=default;
121 friend std::ostream &operator<<(std::ostream &o, CellContent const &cell);
122
124 bool empty() const
125 {
126 if (m_contentType == C_NUMBER) return false;
127 if (m_contentType == C_TEXT && !m_textEntry.valid()) return false;
128 if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
129 return true;
130 }
131
132 void setValue(long double value)
133 {
134 m_value = value;
135 m_valueSet = true;
136 }
137
138 bool isValueSet() const
139 {
140 return m_valueSet;
141 }
142
143 bool hasText() const
144 {
145 return m_textEntry.valid();
146 }
147
148 static bool double2Date(long double val, int &Y, int &M, int &D);
150 static bool double2Time(long double val, int &H, int &M, int &S);
151
155 long double m_value;
161 std::vector<FormulaInstruction> m_formula;
162 };
163
164 WKSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface);
165 ~WKSContentListener() final;
166
167 void setDocumentLanguage(int lcid) final;
168 void setMetaData(const librevenge::RVNGPropertyList &list);
169
170 void startDocument();
171 void endDocument();
172 void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
173
174 // ------ text data -----------
175
177 void insertCharacter(uint8_t character) final;
181 void insertUnicode(uint32_t character) final;
183 void insertUnicodeString(librevenge::RVNGString const &str) final;
184
185 void insertTab() final;
186 void insertEOL(bool softBreak=false) final;
187 void insertBreak(const uint8_t breakType) final;
188
189 // ------ text format -----------
191 void setFont(const WPSFont &font) final;
193 WPSFont const &getFont() const final;
194
195 // ------ paragraph format -----------
197 bool isParagraphOpened() const final;
199 void setParagraph(const WPSParagraph &para) final;
201 WPSParagraph const &getParagraph() const final;
202
203 // ------- fields ----------------
205 void insertField(WPSField const &field) final;
206
207 // ------- subdocument -----------------
209 void insertComment(WPSSubDocumentPtr &subDocument);
211 void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
212 std::string const &type="image/pict", WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle());
214 void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj,
215 WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle());
217 void insertPicture(WPSPosition const &pos, WPSGraphicShape const &shape, WPSGraphicStyle const &style);
219 void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
220 WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle());
222 bool openGroup(WPSPosition const &pos) final;
224 void closeGroup() final;
225
226 // ------- sheet -----------------
228 void openSheet(std::vector<WPSColumnFormat> const &columns, librevenge::RVNGString const &name="");
230 void closeSheet();
232 void openSheetRow(WPSRowFormat const &f, int numRepeated=1);
234 void closeSheetRow();
239 void openSheetCell(WPSCell const &cell, CellContent const &content, int numRepeated=1);
241 void closeSheetCell();
242
243 // ------- chart -----------------
245 void insertChart(WPSPosition const &pos, WKSChart const &chart,
246 WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle());
247protected:
248 void _openPageSpan();
249 void _closePageSpan();
250
251 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos);
252 bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style);
253 void _closeFrame();
254
255 void _startSubDocument();
256 void _endSubDocument();
257
258 void _openParagraph();
259 void _closeParagraph();
260 void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
261 void _resetParagraphState(const bool isListElement=false);
262
263 void _openSpan();
264 void _closeSpan();
265
266 void _flushText();
267 void _flushDeferredTabs();
268
269 void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
270
274 std::shared_ptr<WKSContentParsingState> _pushParsingState();
276 void _popParsingState();
277
278protected:
279 std::shared_ptr<WKSDocumentParsingState> m_ds; // main parse state
280 std::shared_ptr<WKSContentParsingState> m_ps; // parse state
281 std::vector<std::shared_ptr<WKSContentParsingState> > m_psStack;
282 librevenge::RVNGSpreadsheetInterface *m_documentInterface;
283
284private:
286 WKSContentListener &operator=(const WKSContentListener &) = delete;
287};
288
289#endif
290/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
a class used to store a chart associated to a spreadsheet ....
Definition WKSChart.h:46
void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos)
Definition WKSContentListener.cpp:795
std::shared_ptr< WKSContentParsingState > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition WKSContentListener.cpp:1279
bool openGroup(WPSPosition const &pos) final
open a group (not implemented)
Definition WKSContentListener.cpp:690
void setMetaData(const librevenge::RVNGPropertyList &list)
Definition WKSContentListener.cpp:355
void _openParagraph()
Definition WKSContentListener.cpp:403
void _openSpan()
Definition WKSContentListener.cpp:456
WPSFont const & getFont() const final
returns the actual font
Definition WKSContentListener.cpp:299
std::shared_ptr< WKSContentParsingState > m_ps
Definition WKSContentListener.h:280
bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style)
Definition WKSContentListener.cpp:726
void openSheet(std::vector< WPSColumnFormat > const &columns, librevenge::RVNGString const &name="")
open a sheet
Definition WKSContentListener.cpp:1000
void endDocument()
Definition WKSContentListener.cpp:381
void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj, WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle())
adds an object with replacement picture in given position
Definition WKSContentListener.cpp:634
void setParagraph(const WPSParagraph &para) final
sets the actual paragraph
Definition WKSContentListener.cpp:317
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType)
Definition WKSContentListener.cpp:932
void insertBreak(const uint8_t breakType) final
Definition WKSContentListener.cpp:253
void _openPageSpan()
Definition WKSContentListener.cpp:1210
void _resetParagraphState(const bool isListElement=false)
Definition WKSContentListener.cpp:439
void insertComment(WPSSubDocumentPtr &subDocument)
adds comment
Definition WKSContentListener.cpp:545
void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData, std::string const &type="image/pict", WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle())
adds a picture in given position
Definition WKSContentListener.cpp:620
void setDocumentLanguage(int lcid) final
Definition WKSContentListener.cpp:347
librevenge::RVNGSpreadsheetInterface * m_documentInterface
Definition WKSContentListener.h:282
void insertUnicode(uint32_t character) final
adds an unicode character
Definition WKSContentListener.cpp:204
void _flushText()
Definition WKSContentListener.cpp:511
void insertCharacter(uint8_t character) final
adds a basic character, ..
Definition WKSContentListener.cpp:192
void closeSheetRow()
closes this row
Definition WKSContentListener.cpp:1069
void insertField(WPSField const &field) final
adds a field
Definition WKSContentListener.cpp:325
WKSContentListener(std::vector< WPSPageSpan > const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface)
Definition WKSContentListener.cpp:177
std::shared_ptr< WKSDocumentParsingState > m_ds
Definition WKSContentListener.h:279
void _closeFrame()
Definition WKSContentListener.cpp:783
void _closeParagraph()
Definition WKSContentListener.cpp:425
void openSheetCell(WPSCell const &cell, CellContent const &content, int numRepeated=1)
low level function to define a cell.
Definition WKSContentListener.cpp:1080
void startDocument()
Definition WKSContentListener.cpp:365
void insertChart(WPSPosition const &pos, WKSChart const &chart, WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle())
adds a chart in given position
Definition WKSContentListener.cpp:580
void _closePageSpan()
Definition WKSContentListener.cpp:1262
void _startSubDocument()
Definition WKSContentListener.cpp:983
std::vector< std::shared_ptr< WKSContentParsingState > > m_psStack
Definition WKSContentListener.h:281
void closeGroup() final
close a group (not implemented)
Definition WKSContentListener.cpp:714
void openSheetRow(WPSRowFormat const &f, int numRepeated=1)
open a row
Definition WKSContentListener.cpp:1049
~WKSContentListener() final
Definition WKSContentListener.cpp:185
void setFont(const WPSFont &font) final
set the actual font
Definition WKSContentListener.cpp:285
void insertEOL(bool softBreak=false) final
Definition WKSContentListener.cpp:220
WPSParagraph const & getParagraph() const final
returns the actual paragraph
Definition WKSContentListener.cpp:312
void _flushDeferredTabs()
Definition WKSContentListener.cpp:488
void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument, WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle())
adds a textbox in given position
Definition WKSContentListener.cpp:607
void closeSheet()
closes this sheet
Definition WKSContentListener.cpp:1034
void insertTab() final
adds an unicode character to a string ( with correct encoding ).
Definition WKSContentListener.cpp:241
void closeSheetCell()
close a cell
Definition WKSContentListener.cpp:1193
void _closeSpan()
Definition WKSContentListener.cpp:475
void _endSubDocument()
Definition WKSContentListener.cpp:989
void _popParsingState()
resets the previous parsing state
Definition WKSContentListener.cpp:1300
void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false)
Definition WKSContentListener.cpp:446
void insertUnicodeString(librevenge::RVNGString const &str) final
adds a unicode string
Definition WKSContentListener.cpp:213
void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList)
Definition WKSContentListener.cpp:272
bool isParagraphOpened() const final
returns true if a paragraph or a list is opened
Definition WKSContentListener.cpp:307
a structure used to defined the cell format
Definition WPSCell.h:41
a structure used to defined the cell position, and a format
Definition WPSCell.h:291
basic class to store an entry in a file This contained :
Definition WPSEntry.h:39
define the font properties
Definition WPSFont.h:37
a structure used to define a picture shape
Definition WPSGraphicShape.h:35
a structure used to define a picture style
Definition WPSGraphicStyle.h:38
a small structure used to store the informations about a list
Definition WPSList.h:37
WPSListener()
Definition WPSListener.h:39
Definition WPSPageSpan.h:39
Class to define the position of an object (textbox, picture, ..) in the document.
Definition WPSPosition.h:40
std::shared_ptr< WPSSubDocument > WPSSubDocumentPtr
shared pointer to WPSSubDocument
Definition libwps_internal.h:111
Vec2< int > Vec2i
Vec2 of int.
Definition libwps_internal.h:702
Vec2< bool > Vec2b
Vec2 of bool.
Definition libwps_internal.h:700
Definition libwps_internal.cpp:39
small class use to define a sheet cell content
Definition WKSContentListener.h:106
bool m_valueSet
true if the value has been set
Definition WKSContentListener.h:157
bool hasText() const
returns true if the text is set
Definition WKSContentListener.h:143
static bool double2Date(long double val, int &Y, int &M, int &D)
conversion beetween double days since 1900 and date
Definition WKSContentListener.cpp:1466
std::vector< FormulaInstruction > m_formula
the formula list of instruction
Definition WKSContentListener.h:161
~CellContent()
destructor
Definition WKSContentListener.h:119
bool isValueSet() const
returns true if the value has been setted
Definition WKSContentListener.h:138
ContentType m_contentType
the content type ( by default unknown )
Definition WKSContentListener.h:153
CellContent & operator=(CellContent const &)=default
long double m_value
the cell value
Definition WKSContentListener.h:155
CellContent()
constructor
Definition WKSContentListener.h:110
WPSEntry m_textEntry
the cell string
Definition WKSContentListener.h:159
friend std::ostream & operator<<(std::ostream &o, CellContent const &cell)
operator<<
Definition WKSContentListener.cpp:1534
CellContent(CellContent const &)=default
ContentType
the different types of cell's field
Definition WKSContentListener.h:108
@ C_NUMBER
Definition WKSContentListener.h:108
@ C_UNKNOWN
Definition WKSContentListener.h:108
@ C_TEXT
Definition WKSContentListener.h:108
@ C_NONE
Definition WKSContentListener.h:108
@ C_FORMULA
Definition WKSContentListener.h:108
bool empty() const
returns true if the cell has no content
Definition WKSContentListener.h:124
void setValue(long double value)
sets the double value
Definition WKSContentListener.h:132
static bool double2Time(long double val, int &H, int &M, int &S)
conversion beetween double: second since 0:00 and time
Definition WKSContentListener.cpp:1522
small class use to define a formula instruction
Definition WKSContentListener.h:58
Vec2b m_positionRelative[2]
relative cell position ( if type==F_Cell or F_CellList )
Definition WKSContentListener.h:93
int m_sheetId[2]
the sheet id
Definition WKSContentListener.h:100
librevenge::RVNGString m_fileName
the file name (external reference)
Definition WKSContentListener.h:102
double m_longValue
value ( if type==F_Long )
Definition WKSContentListener.h:87
What
Definition WKSContentListener.h:59
@ F_Operator
Definition WKSContentListener.h:59
@ F_Double
Definition WKSContentListener.h:59
@ F_Long
Definition WKSContentListener.h:59
@ F_Function
Definition WKSContentListener.h:59
@ F_CellList
Definition WKSContentListener.h:59
@ F_Cell
Definition WKSContentListener.h:59
@ F_Text
Definition WKSContentListener.h:59
static void add(std::vector< FormulaInstruction > &formula, int n)
add n to a list of instructions
Definition WKSContentListener.cpp:1402
librevenge::RVNGString m_sheetName[2]
the sheet name
Definition WKSContentListener.h:95
librevenge::RVNGPropertyList getPropertyList() const
return a proplist corresponding to a instruction
Definition WKSContentListener.cpp:1312
What m_type
the type
Definition WKSContentListener.h:83
friend std::ostream & operator<<(std::ostream &o, FormulaInstruction const &inst)
operator<<
Definition WKSContentListener.cpp:1428
FormulaInstruction()
constructor
Definition WKSContentListener.h:61
long double m_doubleValue
value ( if type==F_Double )
Definition WKSContentListener.h:89
std::string m_content
the content ( if type == F_Operator or type = F_Function or type==F_Text)
Definition WKSContentListener.h:85
Vec2i m_position[2]
cell position ( if type==F_Cell or F_CellList )
Definition WKSContentListener.h:91
static void enclose(std::vector< FormulaInstruction > &formula, bool force)
add parenthesis (if need) around a list of instructions
Definition WKSContentListener.cpp:1370
the spreadsheet state
Definition WKSContentListener.cpp:87
the document state
Definition WKSContentListener.cpp:50
Definition WPSTable.h:40
small class use to define a embedded object
Definition libwps_internal.h:1077
a field
Definition libwps_internal.h:463
class to store the paragraph properties
Definition WPSParagraph.h:58
Definition WPSTable.h:105
Definition WPSParagraph.h:38

Generated on for libwps by doxygen 1.17.0