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 
46 
48 {
49 public:
52  {
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);
70  std::string m_content;
72  double m_longValue;
74  double m_doubleValue;
79  };
81  struct CellContent
82  {
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 
124  double m_value;
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:
234 };
235 
236 #endif
237 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
std::vector< shared_ptr< WKSContentParsingState > > m_psStack
Definition: WKSContentListener.h:228
void closeSheet()
closes this sheet
Definition: WKSContentListener.cpp:676
CellContent()
constructor
Definition: WKSContentListener.h:86
std::vector< FormulaInstruction > m_formula
the formula list of instruction
Definition: WKSContentListener.h:130
class to store the paragraph properties
Definition: WPSParagraph.h:55
Definition: WKSContentListener.h:53
What
Definition: WKSContentListener.h:53
Definition: WKSContentListener.h:84
void endDocument()
Definition: WKSContentListener.cpp:384
the spreadsheet state
Definition: WKSContentListener.cpp:78
What m_type
the type
Definition: WKSContentListener.h:68
shared_ptr< WPSSubDocument > WPSSubDocumentPtr
shared pointer to WPSSubDocument
Definition: libwps_internal.h:104
double m_longValue
value ( if type==F_Long )
Definition: WKSContentListener.h:72
void closeSheetRow()
closes this row
Definition: WKSContentListener.cpp:714
Definition: WKSContentListener.h:53
void _flushDeferredTabs()
Definition: WKSContentListener.cpp:491
define the font properties
Definition: WPSFont.h:37
void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false)
Definition: WKSContentListener.cpp:449
Definition: WKSContentListener.h:84
virtual class for content listener
Definition: WPSListener.h:36
static bool double2Time(double val, int &H, int &M, int &S)
conversion beetween double: second since 0:00 and time
Definition: WKSContentListener.cpp:1050
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType)
Definition: WKSContentListener.cpp:577
void _openParagraph()
Definition: WKSContentListener.cpp:406
Definition: WKSContentListener.h:84
a structure used to defined the cell format
Definition: WPSCell.h:40
friend std::ostream & operator<<(std::ostream &o, FormulaInstruction const &inst)
operator&lt;&lt;
Definition: WKSContentListener.cpp:1003
void _openSpan()
Definition: WKSContentListener.cpp:459
librevenge::RVNGPropertyList getPropertyList() const
return a proplist corresponding to a instruction
Definition: WKSContentListener.cpp:954
void insertUnicodeString(librevenge::RVNGString const &str)
adds a unicode string
Definition: WKSContentListener.cpp:186
WKSContentListener(std::vector< WPSPageSpan > const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface)
Definition: WKSContentListener.cpp:152
a structure used to defined the cell position, and a format
Definition: WPSCell.h:246
double m_value
the cell value
Definition: WKSContentListener.h:124
void _resetParagraphState(const bool isListElement=false)
Definition: WKSContentListener.cpp:442
Definition: WKSContentListener.h:53
std::string m_content
the content ( if type == F_Operator or type = F_Function or type==F_Text)
Definition: WKSContentListener.h:70
shared_ptr< WKSDocumentParsingState > m_ds
Definition: WKSContentListener.h:226
void insertCharacter(uint8_t character)
adds a basic character, ..
Definition: WKSContentListener.cpp:165
bool isParagraphOpened() const
returns true if a paragraph or a list is opened
Definition: WKSContentListener.cpp:280
Definition: WKSContentListener.h:53
WPSParagraph const & getParagraph() const
returns the actual paragraph
Definition: WKSContentListener.cpp:285
void insertTab()
Definition: WKSContentListener.cpp:214
bool isValueSet() const
returns true if the value has been setted
Definition: WKSContentListener.h:107
WKSContentListener & operator=(const WKSContentListener &)
bool m_valueSet
true if the value has been set
Definition: WKSContentListener.h:126
double m_doubleValue
value ( if type==F_Double )
Definition: WKSContentListener.h:74
shared_ptr< WKSContentParsingState > m_ps
Definition: WKSContentListener.h:227
SubDocumentType
Definition: libwps_internal.h:256
Definition: WKSContentListener.h:84
a small structure used to store the informations about a list
Definition: WPSList.h:36
Vec2b m_positionRelative[2]
relative cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:78
static bool double2Date(double val, int &Y, int &M, int &D)
conversion beetween double days since 1900 and date
Definition: WKSContentListener.cpp:1037
void closeSheetCell()
close a cell
Definition: WKSContentListener.cpp:836
void insertField(FieldType type)
adds a field type
Definition: WKSContentListener.cpp:299
~CellContent()
destructor
Definition: WKSContentListener.h:88
Definition: WKSContentListener.h:53
void _openPageSpan()
Definition: WKSContentListener.cpp:853
bool empty() const
returns true if the cell has no content
Definition: WKSContentListener.h:93
void setFont(const WPSFont &font)
set the actual font
Definition: WKSContentListener.cpp:258
Definition: WKSContentListener.h:53
void _endSubDocument()
Definition: WKSContentListener.cpp:632
Vec2i m_position[2]
cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:76
void setDocumentLanguage(int lcid)
Definition: WKSContentListener.cpp:360
void _popParsingState()
resets the previous parsing state
Definition: WKSContentListener.cpp:942
FieldType
Defines some basic type for field.
Definition: WPSListener.h:126
void setValue(double value)
sets the double value
Definition: WKSContentListener.h:101
void openSheet(std::vector< float > const &colWidth, librevenge::RVNGUnit unit)
open a sheet
Definition: WKSContentListener.cpp:643
void startDocument()
Definition: WKSContentListener.cpp:368
void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList)
Definition: WKSContentListener.cpp:245
WPSFont const & getFont() const
returns the actual font
Definition: WKSContentListener.cpp:272
bool valid(bool checkId=false) const
returns true if the zone length is positive
Definition: WPSEntry.h:78
virtual ~WKSContentListener()
Definition: WKSContentListener.cpp:158
the document state
Definition: WKSContentListener.cpp:46
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
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:481
shared_ptr< WKSContentParsingState > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition: WKSContentListener.cpp:922
librevenge::RVNGSpreadsheetInterface * m_documentInterface
Definition: WKSContentListener.h:229
void _closeParagraph()
Definition: WKSContentListener.cpp:428
small class use to define a sheet cell content
Definition: WKSContentListener.h:81
void _closePageSpan()
Definition: WKSContentListener.cpp:905
void openSheetRow(float h, librevenge::RVNGUnit unit, bool headerRow=false)
open a row with given height.
Definition: WKSContentListener.cpp:691
void _flushText()
Definition: WKSContentListener.cpp:514
void _closeSpan()
Definition: WKSContentListener.cpp:478
WPSEntry m_textEntry
the cell string
Definition: WKSContentListener.h:128
Definition: WKSContentListener.h:84
Definition: WPSParagraph.h:38
void insertDateTimeField(char const *format)
insert a date/time field with given format (see strftime)
Definition: WKSContentListener.cpp:340
Definition: WPSPageSpan.h:38
void setParagraph(const WPSParagraph &para)
sets the actual paragraph
Definition: WKSContentListener.cpp:290
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:37
void insertComment(WPSSubDocumentPtr &subDocument)
adds comment
Definition: WKSContentListener.cpp:548
friend std::ostream & operator<<(std::ostream &o, CellContent const &cell)
operator&lt;&lt;
Definition: WKSContentListener.cpp:1062
ContentType m_contentType
the content type ( by default unknown )
Definition: WKSContentListener.h:122
void insertUnicode(uint32_t character)
adds an unicode character
Definition: WKSContentListener.cpp:177
Definition: WKSContentListener.h:53
small class use to define a formula instruction
Definition: WKSContentListener.h:51
void _startSubDocument()
Definition: WKSContentListener.cpp:626
void insertEOL(bool softBreak=false)
Definition: WKSContentListener.cpp:193
FormulaInstruction()
constructor
Definition: WKSContentListener.h:55
ContentType
the different types of cell&#39;s field
Definition: WKSContentListener.h:84
Definition: WKSContentListener.h:47
void insertBreak(const uint8_t breakType)
Definition: WKSContentListener.cpp:226
Vec2< bool > Vec2b
Vec2 of bool.
Definition: libwps_internal.h:479
bool hasText() const
returns true if the text is set
Definition: WKSContentListener.h:112

Generated on Mon Nov 23 2015 07:09:19 for libwps by doxygen 1.8.5