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 
39 class WPSCellFormat;
40 class WPSGraphicShape;
41 class WPSGraphicStyle;
42 class WPSList;
43 class WPSPageSpan;
44 struct WPSParagraph;
45 struct WPSTabStop;
46 
49 
51 {
52 public:
55  {
59  {
60  for (int i=0; i<2; ++i)
61  {
62  m_position[i]=Vec2i(0,0);
63  m_positionRelative[i]=Vec2b(false,false);
64  }
65  }
67  librevenge::RVNGPropertyList getPropertyList() const;
69  friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
73  std::string m_content;
75  double m_longValue;
77  double m_doubleValue;
83  librevenge::RVNGString m_sheetName;
84  };
86  struct CellContent
87  {
95  friend std::ostream &operator<<(std::ostream &o, CellContent const &cell);
96 
98  bool empty() const
99  {
100  if (m_contentType == C_NUMBER) return false;
101  if (m_contentType == C_TEXT && !m_textEntry.valid()) return false;
102  if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
103  return true;
104  }
106  void setValue(double value)
107  {
108  m_value = value;
109  m_valueSet = true;
110  }
112  bool isValueSet() const
113  {
114  return m_valueSet;
115  }
117  bool hasText() const
118  {
119  return m_textEntry.valid();
120  }
122  static bool double2Date(double val, int &Y, int &M, int &D);
124  static bool double2Time(double val, int &H, int &M, int &S);
125 
129  double m_value;
135  std::vector<FormulaInstruction> m_formula;
136  };
137 
138  WKSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface);
139  virtual ~WKSContentListener();
140 
141  void setDocumentLanguage(int lcid);
142 
143  void startDocument();
144  void endDocument();
145  void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
146 
147  // ------ text data -----------
148 
150  void insertCharacter(uint8_t character);
154  void insertUnicode(uint32_t character);
156  void insertUnicodeString(librevenge::RVNGString const &str);
157 
158  void insertTab();
159  void insertEOL(bool softBreak=false);
160  void insertBreak(const uint8_t breakType);
161 
162  // ------ text format -----------
164  void setFont(const WPSFont &font);
166  WPSFont const &getFont() const;
167 
168  // ------ paragraph format -----------
170  bool isParagraphOpened() const;
172  void setParagraph(const WPSParagraph &para);
174  WPSParagraph const &getParagraph() const;
175 
176  // ------- fields ----------------
178  void insertField(FieldType type);
180  void insertDateTimeField(char const *format);
181 
182  // ------- subdocument -----------------
184  void insertComment(WPSSubDocumentPtr &subDocument);
186  void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
187  std::string type="image/pict", WPSGraphicStyle const &style=WPSGraphicStyle::emptyStyle());
189  void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj,
192  void insertPicture(WPSPosition const &pos, WPSGraphicShape const &shape, WPSGraphicStyle const &style);
194  void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
195  WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle());
196 
197  // ------- sheet -----------------
199  void openSheet(std::vector<float> const &colWidth, librevenge::RVNGUnit unit, librevenge::RVNGString const &name="");
201  void closeSheet();
203  void openSheetRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
205  void closeSheetRow();
210  void openSheetCell(WPSCell const &cell, CellContent const &content, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList());
212  void closeSheetCell();
213 
214 protected:
215  void _openPageSpan();
216  void _closePageSpan();
217 
218  void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos);
219  bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style);
220  void _closeFrame();
221 
222  void _startSubDocument();
223  void _endSubDocument();
224 
225  void _openParagraph();
226  void _closeParagraph();
227  void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
228  void _resetParagraphState(const bool isListElement=false);
229 
230  void _openSpan();
231  void _closeSpan();
232 
233  void _flushText();
234  void _flushDeferredTabs();
235 
236  void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
237 
241  shared_ptr<WKSContentParsingState> _pushParsingState();
243  void _popParsingState();
244 
245 protected:
246  shared_ptr<WKSDocumentParsingState> m_ds; // main parse state
247  shared_ptr<WKSContentParsingState> m_ps; // parse state
248  std::vector<shared_ptr<WKSContentParsingState> > m_psStack;
249  librevenge::RVNGSpreadsheetInterface *m_documentInterface;
250 
251 private:
254 };
255 
256 #endif
257 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
std::vector< shared_ptr< WKSContentParsingState > > m_psStack
Definition: WKSContentListener.h:248
void closeSheet()
closes this sheet
Definition: WKSContentListener.cpp:944
CellContent()
constructor
Definition: WKSContentListener.h:91
bool _openFrame(WPSPosition const &pos, WPSGraphicStyle const &style)
Definition: WKSContentListener.cpp:661
std::vector< FormulaInstruction > m_formula
the formula list of instruction
Definition: WKSContentListener.h:135
class to store the paragraph properties
Definition: WPSParagraph.h:54
void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument, WPSGraphicStyle const &frameStyle=WPSGraphicStyle::emptyStyle())
adds a textbox in given position
Definition: WKSContentListener.cpp:578
Definition: WKSContentListener.h:56
What
Definition: WKSContentListener.h:56
Definition: WKSContentListener.h:89
void openSheet(std::vector< float > const &colWidth, librevenge::RVNGUnit unit, librevenge::RVNGString const &name="")
open a sheet
Definition: WKSContentListener.cpp:909
void endDocument()
Definition: WKSContentListener.cpp:387
the spreadsheet state
Definition: WKSContentListener.cpp:79
What m_type
the type
Definition: WKSContentListener.h:71
shared_ptr< WPSSubDocument > WPSSubDocumentPtr
shared pointer to WPSSubDocument
Definition: libwps_internal.h:110
double m_longValue
value ( if type==F_Long )
Definition: WKSContentListener.h:75
void closeSheetRow()
closes this row
Definition: WKSContentListener.cpp:982
void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos)
Definition: WKSContentListener.cpp:716
Definition: WKSContentListener.h:56
void _flushDeferredTabs()
Definition: WKSContentListener.cpp:494
define the font properties
Definition: WPSFont.h:36
void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false)
Definition: WKSContentListener.cpp:452
Definition: WKSContentListener.h:89
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:1326
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType)
Definition: WKSContentListener.cpp:843
void _openParagraph()
Definition: WKSContentListener.cpp:409
Definition: WKSContentListener.h:89
a structure used to defined the cell format
Definition: WPSCell.h:40
friend std::ostream & operator<<(std::ostream &o, FormulaInstruction const &inst)
operator<<
Definition: WKSContentListener.cpp:1275
void _openSpan()
Definition: WKSContentListener.cpp:462
librevenge::RVNGPropertyList getPropertyList() const
return a proplist corresponding to a instruction
Definition: WKSContentListener.cpp:1222
void insertUnicodeString(librevenge::RVNGString const &str)
adds a unicode string
Definition: WKSContentListener.cpp:189
WKSContentListener(std::vector< WPSPageSpan > const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface)
Definition: WKSContentListener.cpp:155
a structure used to defined the cell position, and a format
Definition: WPSCell.h:251
double m_value
the cell value
Definition: WKSContentListener.h:129
void _resetParagraphState(const bool isListElement=false)
Definition: WKSContentListener.cpp:445
Definition: WKSContentListener.h:56
std::string m_content
the content ( if type == F_Operator or type = F_Function or type==F_Text)
Definition: WKSContentListener.h:73
librevenge::RVNGString m_sheetName
the sheet name
Definition: WKSContentListener.h:83
shared_ptr< WKSDocumentParsingState > m_ds
Definition: WKSContentListener.h:246
void insertCharacter(uint8_t character)
adds a basic character, ..
Definition: WKSContentListener.cpp:168
bool isParagraphOpened() const
returns true if a paragraph or a list is opened
Definition: WKSContentListener.cpp:283
Definition: WKSContentListener.h:56
WPSParagraph const & getParagraph() const
returns the actual paragraph
Definition: WKSContentListener.cpp:288
a structure used to define a picture style
Definition: WPSGraphicStyle.h:37
void insertTab()
adds an unicode character to a string ( with correct encoding ).
Definition: WKSContentListener.cpp:217
bool isValueSet() const
returns true if the value has been setted
Definition: WKSContentListener.h:112
WKSContentListener & operator=(const WKSContentListener &)
void _closeFrame()
Definition: WKSContentListener.cpp:704
static WPSGraphicStyle emptyStyle()
returns an empty style.
Definition: WPSGraphicStyle.h:201
a structure used to define a picture shape
Definition: WPSGraphicShape.h:34
bool m_valueSet
true if the value has been set
Definition: WKSContentListener.h:131
double m_doubleValue
value ( if type==F_Double )
Definition: WKSContentListener.h:77
shared_ptr< WKSContentParsingState > m_ps
Definition: WKSContentListener.h:247
SubDocumentType
Definition: libwps_internal.h:472
Definition: WKSContentListener.h:89
a small structure used to store the informations about a list
Definition: WPSList.h:36
std::string name(long id)
returns the name given Windows© id
Definition: libwps_tools_win.cpp:7296
Vec2b m_positionRelative[2]
relative cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:81
static bool double2Date(double val, int &Y, int &M, int &D)
conversion beetween double days since 1900 and date
Definition: WKSContentListener.cpp:1313
void closeSheetCell()
close a cell
Definition: WKSContentListener.cpp:1104
void insertField(FieldType type)
adds a field type
Definition: WKSContentListener.cpp:302
~CellContent()
destructor
Definition: WKSContentListener.h:93
Definition: WKSContentListener.h:56
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:591
void _openPageSpan()
Definition: WKSContentListener.cpp:1121
bool empty() const
returns true if the cell has no content
Definition: WKSContentListener.h:98
void setFont(const WPSFont &font)
set the actual font
Definition: WKSContentListener.cpp:261
Definition: WKSContentListener.h:56
void _endSubDocument()
Definition: WKSContentListener.cpp:898
Vec2i m_position[2]
cell position ( if type==F_Cell or F_CellList )
Definition: WKSContentListener.h:79
void setDocumentLanguage(int lcid)
Definition: WKSContentListener.cpp:363
void _popParsingState()
resets the previous parsing state
Definition: WKSContentListener.cpp:1210
FieldType
Defines some basic type for field.
Definition: WPSListener.h:76
void setValue(double value)
sets the double value
Definition: WKSContentListener.h:106
void startDocument()
Definition: WKSContentListener.cpp:371
void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList)
Definition: WKSContentListener.cpp:248
WPSFont const & getFont() const
returns the actual font
Definition: WKSContentListener.cpp:275
bool valid(bool checkId=false) const
returns true if the zone length is positive
Definition: WPSEntry.h:78
virtual ~WKSContentListener()
Definition: WKSContentListener.cpp:161
the document state
Definition: WKSContentListener.cpp:47
void openSheetCell(WPSCell const &cell, CellContent const &content, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList())
low level function to define a cell.
Definition: WKSContentListener.cpp:993
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:697
shared_ptr< WKSContentParsingState > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition: WKSContentListener.cpp:1190
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:605
librevenge::RVNGSpreadsheetInterface * m_documentInterface
Definition: WKSContentListener.h:249
void _closeParagraph()
Definition: WKSContentListener.cpp:431
small class use to define a sheet cell content
Definition: WKSContentListener.h:86
void _closePageSpan()
Definition: WKSContentListener.cpp:1173
void openSheetRow(float h, librevenge::RVNGUnit unit, bool headerRow=false)
open a row with given height.
Definition: WKSContentListener.cpp:959
void _flushText()
Definition: WKSContentListener.cpp:517
void _closeSpan()
Definition: WKSContentListener.cpp:481
WPSEntry m_textEntry
the cell string
Definition: WKSContentListener.h:133
Definition: WKSContentListener.h:89
small class use to define a embedded object
Definition: libwps_internal.h:421
Definition: WPSParagraph.h:37
void insertDateTimeField(char const *format)
insert a date/time field with given format (see strftime)
Definition: WKSContentListener.cpp:343
Definition: WPSPageSpan.h:38
void setParagraph(const WPSParagraph &para)
sets the actual paragraph
Definition: WKSContentListener.cpp:293
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:37
void insertComment(WPSSubDocumentPtr &subDocument)
adds comment
Definition: WKSContentListener.cpp:551
friend std::ostream & operator<<(std::ostream &o, CellContent const &cell)
operator<<
Definition: WKSContentListener.cpp:1338
ContentType m_contentType
the content type ( by default unknown )
Definition: WKSContentListener.h:127
void insertUnicode(uint32_t character)
adds an unicode character
Definition: WKSContentListener.cpp:180
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: WPSPosition.h:39
Definition: WKSContentListener.h:56
small class use to define a formula instruction
Definition: WKSContentListener.h:54
void _startSubDocument()
Definition: WKSContentListener.cpp:892
void insertEOL(bool softBreak=false)
Definition: WKSContentListener.cpp:196
FormulaInstruction()
constructor
Definition: WKSContentListener.h:58
ContentType
the different types of cell's field
Definition: WKSContentListener.h:89
Definition: WKSContentListener.h:50
void insertBreak(const uint8_t breakType)
Definition: WKSContentListener.cpp:229
Vec2< bool > Vec2b
Vec2 of bool.
Definition: libwps_internal.h:695
bool hasText() const
returns true if the text is set
Definition: WKSContentListener.h:117

Generated on Fri Oct 9 2015 14:52:48 for libwps by doxygen 1.8.9.1