- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
36 #include "WPSListener.h"
37
38 class WPSCellFormat;
39 class WPSList;
40 class WPSPageSpan;
41 struct WPSParagraph;
42 struct WPSTabStop;
43
44 struct WKSContentParsingState;
45 struct WKSDocumentParsingState;
46
47 class WKSContentListener : public WPSListener
48 {
49 public:
51 struct FormulaInstruction
52 {
53 enum What { F_Operator, F_Function, F_Cell, F_CellList, F_Long, F_Double, F_Text };
55 FormulaInstruction() : m_type(F_Text), m_content(""), m_longValue(0), m_doubleValue(0)
56 {
57 for (int i=0; i<2; ++i)
58 {
59 m_position[i]=Vec2i(0,0);
60 m_positionRelative[i]=Vec2b(false,false);
61 }
62 }
64 librevenge::RVNGPropertyList getPropertyList() const;
66 friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
68 What m_type;
70 std::string m_content;
72 double m_longValue;
74 double m_doubleValue;
76 Vec2i m_position[2];
78 Vec2b m_positionRelative[2];
79 };
81 struct CellContent
82 {
84 enum ContentType { C_NONE, C_TEXT, C_NUMBER, C_FORMULA, C_UNKNOWN };
86 CellContent() : m_contentType(C_UNKNOWN), m_value(0.0), m_valueSet(false), m_textEntry(), m_formula() { }
88 ~CellContent() {}
90 friend std::ostream &operator<<(std::ostream &o, CellContent const &cell);
91
93 bool empty() const
94 {
95 if (m_contentType == C_NUMBER) return false;
96 if (m_contentType == C_TEXT && !m_textEntry.valid()) return false;
97 if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
98 return true;
99 }
101 void setValue(double value)
102 {
103 m_value = value;
104 m_valueSet = true;
105 }
107 bool isValueSet() const
108 {
109 return m_valueSet;
110 }
112 bool hasText() const
113 {
114 return m_textEntry.valid();
115 }
117 static bool double2Date(double val, int &Y, int &M, int &D);
119 static bool double2Time(double val, int &H, int &M, int &S);
120
122 ContentType m_contentType;
124 double m_value;
126 bool m_valueSet;
128 WPSEntry m_textEntry;
130 std::vector<FormulaInstruction> m_formula;
131 };
132
133 WKSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface);
134 virtual ~WKSContentListener();
135
136 void setDocumentLanguage(int lcid);
137
138 void startDocument();
139 void endDocument();
140 void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
141
142 // ------ text data -----------
143
145 void insertCharacter(uint8_t character);
149 void insertUnicode(uint32_t character);
151 void insertUnicodeString(librevenge::RVNGString const &str);
152
153 void insertTab();
154 void insertEOL(bool softBreak=false);
155 void insertBreak(const uint8_t breakType);
156
157 // ------ text format -----------
159 void setFont(const WPSFont &font);
161 WPSFont const &getFont() const;
162
163 // ------ paragraph format -----------
165 bool isParagraphOpened() const;
167 void setParagraph(const WPSParagraph &para);
169 WPSParagraph const &getParagraph() const;
170
171 // ------- fields ----------------
173 void insertField(FieldType type);
175 void insertDateTimeField(char const *format);
176
177 // ------- subdocument -----------------
179 void insertComment(WPSSubDocumentPtr &subDocument);
180
181 // ------- sheet -----------------
183 void openSheet(std::vector<float> const &colWidth, librevenge::RVNGUnit unit);
185 void closeSheet();
187 void openSheetRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
189 void closeSheetRow();
194 void openSheetCell(WPSCell const &cell, CellContent const &content, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList());
196 void closeSheetCell();
197
198 protected:
199 void _openPageSpan();
200 void _closePageSpan();
201
202 void _startSubDocument();
203 void _endSubDocument();
204
205 void _openParagraph();
206 void _closeParagraph();
207 void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
208 void _resetParagraphState(const bool isListElement=false);
209
210 void _openSpan();
211 void _closeSpan();
212
213 void _flushText();
214 void _flushDeferredTabs();
215
216 void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
217
221 shared_ptr<WKSContentParsingState> _pushParsingState();
223 void _popParsingState();
224
225 protected:
226 shared_ptr<WKSDocumentParsingState> m_ds; // main parse state
227 shared_ptr<WKSContentParsingState> m_ps; // parse state
228 std::vector<shared_ptr<WKSContentParsingState> > m_psStack;
229 librevenge::RVNGSpreadsheetInterface *m_documentInterface;
230
231 private:
232 WKSContentListener(const WKSContentListener &);
233 WKSContentListener &operator=(const WKSContentListener &);
234 };
235
236 #endif
237 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WKSContentListener::m_psStack
std::vector< shared_ptr< WKSContentParsingState > > m_psStack
Definition: WKSContentListener.h:228
WKSContentListener::closeSheet
void closeSheet()
closes this sheet
Definition: WKSContentListener.cpp:676
WKSContentListener::CellContent::CellContent
CellContent()
constructor
Definition: WKSContentListener.h:86
WKSContentListener::CellContent::m_formula
std::vector< FormulaInstruction > m_formula
the formula list of instruction
Definition: WKSContentListener.h:130
WPSParagraph
class to store the paragraph properties
Definition: WPSParagraph.h:55
WKSContentListener::FormulaInstruction::F_Function
Definition: WKSContentListener.h:53
WKSContentListener::FormulaInstruction::What
What
Definition: WKSContentListener.h:53
WKSContentListener::CellContent::C_NONE
Definition: WKSContentListener.h:84
WKSContentListener::endDocument
void endDocument()
Definition: WKSContentListener.cpp:384
WKSContentParsingState
the spreadsheet state
Definition: WKSContentListener.cpp:78
WKSContentListener::FormulaInstruction::m_type
What m_type
the type
Definition: WKSContentListener.h:68
WPSSubDocumentPtr
shared_ptr< WPSSubDocument > WPSSubDocumentPtr
shared pointer to WPSSubDocument
Definition: libwps_internal.h:104
WKSContentListener::FormulaInstruction::m_longValue
double m_longValue
value ( if type==F_Long )
Definition: WKSContentListener.h:72
WKSContentListener::closeSheetRow
void closeSheetRow()
closes this row
Definition: WKSContentListener.cpp:714
WKSContentListener::FormulaInstruction::F_Cell
Definition: WKSContentListener.h:53
WKSContentListener::_flushDeferredTabs
void _flushDeferredTabs()
Definition: WKSContentListener.cpp:491
WPSFont
define the font properties
Definition: WPSFont.h:37
WKSContentListener::_appendParagraphProperties
void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false)
Definition: WKSContentListener.cpp:449
WKSContentListener::CellContent::C_TEXT
Definition: WKSContentListener.h:84
WPSListener
virtual class for content listener
Definition: WPSListener.h:36
WKSContentListener::CellContent::double2Time
static bool double2Time(double val, int &H, int &M, int &S)
conversion beetween double: second since 0:00 and time
Definition: WKSContentListener.cpp:1050
WKSContentListener::handleSubDocument
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType)
Definition: WKSContentListener.cpp:577
WKSContentListener::_openParagraph
void _openParagraph()
Definition: WKSContentListener.cpp:406
WKSContentListener::CellContent::C_UNKNOWN
Definition: WKSContentListener.h:84
WPSCellFormat
a structure used to defined the cell format
Definition: WPSCell.h:40
WKSContentListener::FormulaInstruction::operator<<
friend std::ostream & operator<<(std::ostream &o, FormulaInstruction const &inst)
operator<<
Definition: WKSContentListener.cpp:1003
WKSContentListener::_openSpan
void _openSpan()
Definition: WKSContentListener.cpp:459
WKSContentListener::FormulaInstruction::getPropertyList
librevenge::RVNGPropertyList getPropertyList() const
return a proplist corresponding to a instruction
Definition: WKSContentListener.cpp:954
WKSContentListener::insertUnicodeString
void insertUnicodeString(librevenge::RVNGString const &str)
adds a unicode string
Definition: WKSContentListener.cpp:186
WKSContentListener::WKSContentListener
WKSContentListener(std::vector< WPSPageSpan > const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface)
Definition: WKSContentListener.cpp:152
WPSCell
a structure used to defined the cell position, and a format
Definition: WPSCell.h:246
WKSContentListener::CellContent::m_value
double m_value
the cell value
Definition: WKSContentListener.h:124
WKSContentListener::_resetParagraphState
void _resetParagraphState(const bool isListElement=false)
Definition: WKSContentListener.cpp:442
WKSContentListener::FormulaInstruction::F_Operator
Definition: WKSContentListener.h:53
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:70
WKSContentListener::m_ds
shared_ptr< WKSDocumentParsingState > m_ds
Definition: WKSContentListener.h:226
WKSContentListener::insertCharacter
void insertCharacter(uint8_t character)
adds a basic character, ..
Definition: WKSContentListener.cpp:165
WKSContentListener::isParagraphOpened
bool isParagraphOpened() const
returns true if a paragraph or a list is opened
Definition: WKSContentListener.cpp:280
WKSContentListener::FormulaInstruction::F_CellList
Definition: WKSContentListener.h:53
WKSContentListener::getParagraph
WPSParagraph const & getParagraph() const
returns the actual paragraph
Definition: WKSContentListener.cpp:285
WKSContentListener::insertTab
void insertTab()
Definition: WKSContentListener.cpp:214
WKSContentListener::CellContent::isValueSet
bool isValueSet() const
returns true if the value has been setted
Definition: WKSContentListener.h:107
WKSContentListener::operator=
WKSContentListener & operator=(const WKSContentListener &)
WKSContentListener::CellContent::m_valueSet
bool m_valueSet
true if the value has been set
Definition: WKSContentListener.h:126
libwps_internal.h
WKSContentListener::FormulaInstruction::m_doubleValue
double m_doubleValue
value ( if type==F_Double )
Definition: WKSContentListener.h:74
WKSContentListener::m_ps
shared_ptr< WKSContentParsingState > m_ps
Definition: WKSContentListener.h:227
libwps::SubDocumentType
SubDocumentType
Definition: libwps_internal.h:256
WKSContentListener::CellContent::C_FORMULA
Definition: WKSContentListener.h:84
WPSList
a small structure used to store the informations about a list
Definition: WPSList.h:36
WPSEntry.h
WKSContentListener::FormulaInstruction::m_positionRelative
Vec2b m_positionRelative[2]
relative cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:78
WKSContentListener::CellContent::double2Date
static bool double2Date(double val, int &Y, int &M, int &D)
conversion beetween double days since 1900 and date
Definition: WKSContentListener.cpp:1037
WKSContentListener::closeSheetCell
void closeSheetCell()
close a cell
Definition: WKSContentListener.cpp:836
WKSContentListener::insertField
void insertField(FieldType type)
adds a field type
Definition: WKSContentListener.cpp:299
WKSContentListener::CellContent::~CellContent
~CellContent()
destructor
Definition: WKSContentListener.h:88
WKSContentListener::FormulaInstruction::F_Double
Definition: WKSContentListener.h:53
WKSContentListener::_openPageSpan
void _openPageSpan()
Definition: WKSContentListener.cpp:853
WKSContentListener::CellContent::empty
bool empty() const
returns true if the cell has no content
Definition: WKSContentListener.h:93
WKSContentListener::setFont
void setFont(const WPSFont &font)
set the actual font
Definition: WKSContentListener.cpp:258
WKSContentListener::FormulaInstruction::F_Text
Definition: WKSContentListener.h:53
WKSContentListener::_endSubDocument
void _endSubDocument()
Definition: WKSContentListener.cpp:632
WKSContentListener::FormulaInstruction::m_position
Vec2i m_position[2]
cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:76
WKSContentListener::setDocumentLanguage
void setDocumentLanguage(int lcid)
Definition: WKSContentListener.cpp:360
WKSContentListener::_popParsingState
void _popParsingState()
resets the previous parsing state
Definition: WKSContentListener.cpp:942
WPSListener::FieldType
FieldType
Defines some basic type for field.
Definition: WPSListener.h:126
WKSContentListener::CellContent::setValue
void setValue(double value)
sets the double value
Definition: WKSContentListener.h:101
WKSContentListener::openSheet
void openSheet(std::vector< float > const &colWidth, librevenge::RVNGUnit unit)
open a sheet
Definition: WKSContentListener.cpp:643
WKSContentListener::startDocument
void startDocument()
Definition: WKSContentListener.cpp:368
WKSContentListener::_insertBreakIfNecessary
void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList)
Definition: WKSContentListener.cpp:245
WKSContentListener::getFont
WPSFont const & getFont() const
returns the actual font
Definition: WKSContentListener.cpp:272
WPSEntry::valid
bool valid(bool checkId=false) const
returns true if the zone length is positive
Definition: WPSEntry.h:78
WKSContentListener::~WKSContentListener
virtual ~WKSContentListener()
Definition: WKSContentListener.cpp:158
WKSDocumentParsingState
the document state
Definition: WKSContentListener.cpp:46
WKSContentListener::openSheetCell
void openSheetCell(WPSCell const &cell, CellContent const &content, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList())
low level function to define a cell.
Definition: WKSContentListener.cpp:725
Vec2i
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:481
WKSContentListener::_pushParsingState
shared_ptr< WKSContentParsingState > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition: WKSContentListener.cpp:922
WKSContentListener::m_documentInterface
librevenge::RVNGSpreadsheetInterface * m_documentInterface
Definition: WKSContentListener.h:229
WKSContentListener::_closeParagraph
void _closeParagraph()
Definition: WKSContentListener.cpp:428
WKSContentListener::CellContent
small class use to define a sheet cell content
Definition: WKSContentListener.h:81
WKSContentListener::_closePageSpan
void _closePageSpan()
Definition: WKSContentListener.cpp:905
WKSContentListener::openSheetRow
void openSheetRow(float h, librevenge::RVNGUnit unit, bool headerRow=false)
open a row with given height.
Definition: WKSContentListener.cpp:691
WKSContentListener::_flushText
void _flushText()
Definition: WKSContentListener.cpp:514
WKSContentListener::_closeSpan
void _closeSpan()
Definition: WKSContentListener.cpp:478
WKSContentListener::CellContent::m_textEntry
WPSEntry m_textEntry
the cell string
Definition: WKSContentListener.h:128
WPSListener.h
WKSContentListener::CellContent::C_NUMBER
Definition: WKSContentListener.h:84
WPSTabStop
Definition: WPSParagraph.h:38
WKSContentListener::insertDateTimeField
void insertDateTimeField(char const *format)
insert a date/time field with given format (see strftime)
Definition: WKSContentListener.cpp:340
WPSPageSpan
Definition: WPSPageSpan.h:38
WKSContentListener::setParagraph
void setParagraph(const WPSParagraph &para)
sets the actual paragraph
Definition: WKSContentListener.cpp:290
WPSEntry
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:37
Vec2< int >
WKSContentListener::insertComment
void insertComment(WPSSubDocumentPtr &subDocument)
adds comment
Definition: WKSContentListener.cpp:548
WKSContentListener::CellContent::operator<<
friend std::ostream & operator<<(std::ostream &o, CellContent const &cell)
operator<<
Definition: WKSContentListener.cpp:1062
WKSContentListener::CellContent::m_contentType
ContentType m_contentType
the content type ( by default unknown )
Definition: WKSContentListener.h:122
WKSContentListener::insertUnicode
void insertUnicode(uint32_t character)
adds an unicode character
Definition: WKSContentListener.cpp:177
WKSContentListener::FormulaInstruction::F_Long
Definition: WKSContentListener.h:53
WKSContentListener::FormulaInstruction
small class use to define a formula instruction
Definition: WKSContentListener.h:51
WKSContentListener::_startSubDocument
void _startSubDocument()
Definition: WKSContentListener.cpp:626
WKSContentListener::insertEOL
void insertEOL(bool softBreak=false)
Definition: WKSContentListener.cpp:193
WKSContentListener::FormulaInstruction::FormulaInstruction
FormulaInstruction()
constructor
Definition: WKSContentListener.h:55
WKSContentListener::CellContent::ContentType
ContentType
the different types of cell's field
Definition: WKSContentListener.h:84
WKSContentListener
Definition: WKSContentListener.h:47
WKSContentListener::insertBreak
void insertBreak(const uint8_t breakType)
Definition: WKSContentListener.cpp:226
Vec2b
Vec2< bool > Vec2b
Vec2 of bool.
Definition: libwps_internal.h:479
WKSContentListener::CellContent::hasText
bool hasText() const
returns true if the text is set
Definition: WKSContentListener.h:112