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;
40struct WPSColumnFormat;
41class WPSGraphicShape;
42class WPSGraphicStyle;
43class WPSList;
44class WPSPageSpan;
45struct WPSParagraph;
46struct WPSRowFormat;
47struct WPSTabStop;
48
51
53{
54public:
57 {
61 {
62 for (int i=0; i<2; ++i)
63 {
64 m_position[i]=Vec2i(0,0);
65 m_positionRelative[i]=Vec2b(false,false);
66 }
67 }
69 librevenge::RVNGPropertyList getPropertyList() const;
71 friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
75 std::string m_content;
85 librevenge::RVNGString m_sheetName;
86 };
89 {
97 friend std::ostream &operator<<(std::ostream &o, CellContent const &cell);
98
100 bool empty() const
101 {
102 if (m_contentType == C_NUMBER) return false;
103 if (m_contentType == C_TEXT && !m_textEntry.valid()) return false;
104 if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
105 return true;
106 }
108 void setValue(double value)
109 {
110 m_value = value;
111 m_valueSet = true;
112 }
114 bool isValueSet() const
115 {
116 return m_valueSet;
117 }
119 bool hasText() const
120 {
121 return m_textEntry.valid();
122 }
124 static bool double2Date(double val, int &Y, int &M, int &D);
126 static bool double2Time(double val, int &H, int &M, int &S);
127
131 double m_value;
137 std::vector<FormulaInstruction> m_formula;
138 };
139
140 WKSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface);
141 virtual ~WKSContentListener();
142
143 void setDocumentLanguage(int lcid);
144 void setMetaData(const librevenge::RVNGPropertyList &list);
145
146 void startDocument();
147 void endDocument();
148 void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
149
150 // ------ text data -----------
151
153 void insertCharacter(uint8_t character);
157 void insertUnicode(uint32_t character);
159 void insertUnicodeString(librevenge::RVNGString const &str);
160
161 void insertTab();
162 void insertEOL(bool softBreak=false);
163 void insertBreak(const uint8_t breakType);
164
165 // ------ text format -----------
167 void setFont(const WPSFont &font);
169 WPSFont const &getFont() const;
170
171 // ------ paragraph format -----------
173 bool isParagraphOpened() const;
175 void setParagraph(const WPSParagraph &para);
177 WPSParagraph const &getParagraph() const;
178
179 // ------- fields ----------------
181 void insertField(WPSField const &field);
182
183 // ------- subdocument -----------------
185 void insertComment(WPSSubDocumentPtr &subDocument);
187 void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
188 std::string type="image/pict", WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle());
190 void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj,
193 void insertPicture(WPSPosition const &pos, WPSGraphicShape const &shape, WPSGraphicStyle const &style);
195 void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
196 WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle());
198 bool openGroup(WPSPosition const &pos);
200 void closeGroup();
201
202 // ------- sheet -----------------
204 void openSheet(std::vector<WPSColumnFormat> const &columns, librevenge::RVNGString const &name="");
206 void closeSheet();
208 void openSheetRow(WPSRowFormat const &f, int numRepeated=1);
210 void closeSheetRow();
215 void openSheetCell(WPSCell const &cell, CellContent const &content, int numRepeated=1);
217 void closeSheetCell();
218
219protected:
220 void _openPageSpan();
221 void _closePageSpan();
222
223 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos);
224 bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style);
225 void _closeFrame();
226
227 void _startSubDocument();
228 void _endSubDocument();
229
230 void _openParagraph();
231 void _closeParagraph();
232 void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
233 void _resetParagraphState(const bool isListElement=false);
234
235 void _openSpan();
236 void _closeSpan();
237
238 void _flushText();
239 void _flushDeferredTabs();
240
241 void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
242
246 shared_ptr<WKSContentParsingState> _pushParsingState();
248 void _popParsingState();
249
250protected:
251 shared_ptr<WKSDocumentParsingState> m_ds; // main parse state
252 shared_ptr<WKSContentParsingState> m_ps; // parse state
253 std::vector<shared_ptr<WKSContentParsingState> > m_psStack;
254 librevenge::RVNGSpreadsheetInterface *m_documentInterface;
255
256private:
259};
260
261#endif
262/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Definition: WKSContentListener.h:53
void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos)
Definition: WKSContentListener.cpp:730
void setMetaData(const librevenge::RVNGPropertyList &list)
Definition: WKSContentListener.cpp:334
void setFont(const WPSFont &font)
set the actual font
Definition: WKSContentListener.cpp:264
shared_ptr< WKSContentParsingState > m_ps
Definition: WKSContentListener.h:252
void setDocumentLanguage(int lcid)
Definition: WKSContentListener.cpp:326
WKSContentListener(const WKSContentListener &)
void _openParagraph()
Definition: WKSContentListener.cpp:382
void _openSpan()
Definition: WKSContentListener.cpp:435
bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style)
Definition: WKSContentListener.cpp:675
bool openGroup(WPSPosition const &pos)
open a group (not implemented)
Definition: WKSContentListener.cpp:639
void openSheet(std::vector< WPSColumnFormat > const &columns, librevenge::RVNGString const &name="")
open a sheet
Definition: WKSContentListener.cpp:923
void endDocument()
Definition: WKSContentListener.cpp:360
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:583
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType)
Definition: WKSContentListener.cpp:857
WPSFont const & getFont() const
returns the actual font
Definition: WKSContentListener.cpp:278
void insertCharacter(uint8_t character)
adds a basic character, ..
Definition: WKSContentListener.cpp:171
void _openPageSpan()
Definition: WKSContentListener.cpp:1133
void _resetParagraphState(const bool isListElement=false)
Definition: WKSContentListener.cpp:418
WPSParagraph const & getParagraph() const
returns the actual paragraph
Definition: WKSContentListener.cpp:291
void insertComment(WPSSubDocumentPtr &subDocument)
adds comment
Definition: WKSContentListener.cpp:524
void insertUnicode(uint32_t character)
adds an unicode character
Definition: WKSContentListener.cpp:183
librevenge::RVNGSpreadsheetInterface * m_documentInterface
Definition: WKSContentListener.h:254
void _flushText()
Definition: WKSContentListener.cpp:490
void insertBreak(const uint8_t breakType)
Definition: WKSContentListener.cpp:232
void closeSheetRow()
closes this row
Definition: WKSContentListener.cpp:992
void _closeFrame()
Definition: WKSContentListener.cpp:718
void _closeParagraph()
Definition: WKSContentListener.cpp:404
void openSheetCell(WPSCell const &cell, CellContent const &content, int numRepeated=1)
low level function to define a cell.
Definition: WKSContentListener.cpp:1003
void startDocument()
Definition: WKSContentListener.cpp:344
void _closePageSpan()
Definition: WKSContentListener.cpp:1185
void insertEOL(bool softBreak=false)
Definition: WKSContentListener.cpp:199
WKSContentListener & operator=(const WKSContentListener &)
void _startSubDocument()
Definition: WKSContentListener.cpp:906
shared_ptr< WKSContentParsingState > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition: WKSContentListener.cpp:1202
void insertUnicodeString(librevenge::RVNGString const &str)
adds a unicode string
Definition: WKSContentListener.cpp:192
void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData, std::string type="image/pict", WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle())
adds a picture in given position
Definition: WKSContentListener.cpp:569
void openSheetRow(WPSRowFormat const &f, int numRepeated=1)
open a row
Definition: WKSContentListener.cpp:972
shared_ptr< WKSDocumentParsingState > m_ds
Definition: WKSContentListener.h:251
virtual ~WKSContentListener()
Definition: WKSContentListener.cpp:164
void insertTab()
adds an unicode character to a string ( with correct encoding ).
Definition: WKSContentListener.cpp:220
void _flushDeferredTabs()
Definition: WKSContentListener.cpp:467
void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument, WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle())
adds a textbox in given position
Definition: WKSContentListener.cpp:556
void closeSheet()
closes this sheet
Definition: WKSContentListener.cpp:957
void closeSheetCell()
close a cell
Definition: WKSContentListener.cpp:1116
std::vector< shared_ptr< WKSContentParsingState > > m_psStack
Definition: WKSContentListener.h:253
void setParagraph(const WPSParagraph &para)
sets the actual paragraph
Definition: WKSContentListener.cpp:296
void _closeSpan()
Definition: WKSContentListener.cpp:454
void _endSubDocument()
Definition: WKSContentListener.cpp:912
void insertField(WPSField const &field)
adds a field
Definition: WKSContentListener.cpp:304
void closeGroup()
close a group (not implemented)
Definition: WKSContentListener.cpp:663
void _popParsingState()
resets the previous parsing state
Definition: WKSContentListener.cpp:1223
void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false)
Definition: WKSContentListener.cpp:425
bool isParagraphOpened() const
returns true if a paragraph or a list is opened
Definition: WKSContentListener.cpp:286
void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList)
Definition: WKSContentListener.cpp:251
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:278
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:39
bool valid(bool checkId=false) const
returns true if the zone length is positive
Definition: WPSEntry.h:78
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
static WPSGraphicStyle emptyStyle()
returns an empty style.
Definition: WPSGraphicStyle.h:201
a small structure used to store the informations about a list
Definition: WPSList.h:37
virtual class for content listener
Definition: WPSListener.h:37
Definition: WPSPageSpan.h:39
Class to define the position of an object (textbox, picture, ..) in the document.
Definition: WPSPosition.h:40
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:719
Vec2< bool > Vec2b
Vec2 of bool.
Definition: libwps_internal.h:717
shared_ptr< WPSSubDocument > WPSSubDocumentPtr
shared pointer to WPSSubDocument
Definition: libwps_internal.h:112
SubDocumentType
Definition: libwps_internal.h:246
small class use to define a sheet cell content
Definition: WKSContentListener.h:89
static bool double2Date(double val, int &Y, int &M, int &D)
conversion beetween double days since 1900 and date
Definition: WKSContentListener.cpp:1326
bool m_valueSet
true if the value has been set
Definition: WKSContentListener.h:133
bool hasText() const
returns true if the text is set
Definition: WKSContentListener.h:119
std::vector< FormulaInstruction > m_formula
the formula list of instruction
Definition: WKSContentListener.h:137
~CellContent()
destructor
Definition: WKSContentListener.h:95
void setValue(double value)
sets the double value
Definition: WKSContentListener.h:108
bool isValueSet() const
returns true if the value has been setted
Definition: WKSContentListener.h:114
static bool double2Time(double val, int &H, int &M, int &S)
conversion beetween double: second since 0:00 and time
Definition: WKSContentListener.cpp:1382
ContentType m_contentType
the content type ( by default unknown )
Definition: WKSContentListener.h:129
friend std::ostream & operator<<(std::ostream &o, CellContent const &cell)
operator<<
Definition: WKSContentListener.cpp:1394
double m_value
the cell value
Definition: WKSContentListener.h:131
CellContent()
constructor
Definition: WKSContentListener.h:93
WPSEntry m_textEntry
the cell string
Definition: WKSContentListener.h:135
ContentType
the different types of cell's field
Definition: WKSContentListener.h:91
@ C_NUMBER
Definition: WKSContentListener.h:91
@ C_UNKNOWN
Definition: WKSContentListener.h:91
@ C_TEXT
Definition: WKSContentListener.h:91
@ C_NONE
Definition: WKSContentListener.h:91
@ C_FORMULA
Definition: WKSContentListener.h:91
bool empty() const
returns true if the cell has no content
Definition: WKSContentListener.h:100
small class use to define a formula instruction
Definition: WKSContentListener.h:57
Vec2b m_positionRelative[2]
relative cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:83
double m_longValue
value ( if type==F_Long )
Definition: WKSContentListener.h:77
What
Definition: WKSContentListener.h:58
@ F_Operator
Definition: WKSContentListener.h:58
@ F_Double
Definition: WKSContentListener.h:58
@ F_Long
Definition: WKSContentListener.h:58
@ F_Function
Definition: WKSContentListener.h:58
@ F_CellList
Definition: WKSContentListener.h:58
@ F_Cell
Definition: WKSContentListener.h:58
@ F_Text
Definition: WKSContentListener.h:58
friend std::ostream & operator<<(std::ostream &o, FormulaInstruction const &inst)
operator<<
Definition: WKSContentListener.cpp:1288
double m_doubleValue
value ( if type==F_Double )
Definition: WKSContentListener.h:79
librevenge::RVNGPropertyList getPropertyList() const
return a proplist corresponding to a instruction
Definition: WKSContentListener.cpp:1235
What m_type
the type
Definition: WKSContentListener.h:73
FormulaInstruction()
constructor
Definition: WKSContentListener.h:60
std::string m_content
the content ( if type == F_Operator or type = F_Function or type==F_Text)
Definition: WKSContentListener.h:75
librevenge::RVNGString m_sheetName
the sheet name
Definition: WKSContentListener.h:85
Vec2i m_position[2]
cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:81
the spreadsheet state
Definition: WKSContentListener.cpp:81
the document state
Definition: WKSContentListener.cpp:49
Definition: WPSTable.h:40
small class use to define a embedded object
Definition: libwps_internal.h:439
a field
Definition: libwps_internal.h:487
class to store the paragraph properties
Definition: WPSParagraph.h:55
Definition: WPSTable.h:101
Definition: WPSParagraph.h:38

Generated on Fri Sep 30 2022 11:47:43 for libwps by doxygen 1.9.5