MWAWContentListener.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33 
34 #ifndef MWAW_CONTENT_LISTENER_H
35 #define MWAW_CONTENT_LISTENER_H
36 
37 #include <vector>
38 
39 #include <libwpd/libwpd.h>
40 
41 #include "libmwaw_internal.hxx"
42 
43 class WPXBinaryData;
44 class WPXDocumentInterface;
45 class WPXString;
46 class WPXPropertyListVector;
47 
48 class MWAWCell;
49 class MWAWFont;
50 class MWAWInputStream;
51 class MWAWList;
52 class MWAWPageSpan;
53 class MWAWParagraph;
54 class MWAWParserState;
55 class MWAWPosition;
57 
58 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
59 typedef shared_ptr<MWAWSubDocument> MWAWSubDocumentPtr;
60 
61 namespace MWAWContentListenerInternal
62 {
63 struct DocumentState;
64 struct State;
65 }
66 
68 {
69 public:
71 
73  MWAWContentListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
75  virtual ~MWAWContentListener();
76 
78  void setDocumentLanguage(std::string locale);
79 
81  void startDocument();
83  void endDocument(bool sendDelayedSubDoc=true);
84 
86  void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
88  bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
90  bool isHeaderFooterOpened() const;
91 
92  // ------ text data -----------
93 
95  void insertChar(uint8_t character);
98  void insertCharacter(unsigned char c);
104  int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
107  void insertUnicode(uint32_t character);
109  void insertUnicodeString(WPXString const &str);
110 
112  void insertTab();
114  void insertEOL(bool softBreak=false);
116  void insertBreak(BreakType breakType);
117 
118  // ------ text format -----------
120  void setFont(MWAWFont const &font);
122  MWAWFont const &getFont() const;
123 
124  // ------ paragraph format -----------
126  bool isParagraphOpened() const;
128  void setParagraph(MWAWParagraph const &paragraph);
130  MWAWParagraph const &getParagraph() const;
131 
132  // ------ list format -----------
134  void setList(shared_ptr<MWAWList> list);
135 
136  // ------- fields ----------------
140  void insertField(FieldType type);
142  void insertDateTimeField(char const *format);
143 
144  // ------- subdocument -----------------
148  void insertNote(const NoteType noteType, MWAWSubDocumentPtr &subDocument);
150  void insertLabelNote(const NoteType noteType, WPXString const &label, MWAWSubDocumentPtr &subDocument);
152  void resetNoteNumber(const NoteType noteType, int number);
153 
155  void insertComment(MWAWSubDocumentPtr &subDocument);
156 
158  void insertPicture(MWAWPosition const &pos, const WPXBinaryData &binaryData,
159  std::string type="image/pict",
160  WPXPropertyList frameExtras=WPXPropertyList());
162  void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument,
163  WPXPropertyList frameExtras=WPXPropertyList(),
164  WPXPropertyList textboxExtras=WPXPropertyList());
165 
166  // ------- table -----------------
168  void openTable(std::vector<float> const &colWidth, WPXUnit unit,
169  WPXPropertyList tableExtras=WPXPropertyList());
171  void closeTable();
173  void openTableRow(float h, WPXUnit unit, bool headerRow=false);
175  void closeTableRow();
179  void openTableCell(MWAWCell const &cell, WPXPropertyList const &extras);
181  void closeTableCell();
183  void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
184 
185  // ------- section ---------------
187  bool isSectionOpened() const;
189  int getSectionNumColumns() const;
191  bool openSection(std::vector<int> colsWidth=std::vector<int>(), WPXUnit unit=WPX_POINT);
193  bool closeSection();
194 
195 protected:
196  void _openSection();
197  void _closeSection();
198 
199  void _openPageSpan(bool sendHeaderFooters=true);
200  void _closePageSpan();
201 
202  void _startSubDocument();
203  void _endSubDocument();
204 
205  void _handleFrameParameters( WPXPropertyList &propList, MWAWPosition const &pos);
206  bool openFrame(MWAWPosition const &pos, WPXPropertyList extras=WPXPropertyList());
207  void closeFrame();
208 
209 
210  void _openParagraph();
211  void _closeParagraph();
212  void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
213  void _resetParagraphState(const bool isListElement=false);
214 
216  void _openListElement();
218  void _closeListElement();
220  void _changeList();
225  int _getListId() const;
226 
227  void _openSpan();
228  void _closeSpan();
229 
230  void _flushText();
231  void _flushDeferredTabs();
232 
233  void _insertBreakIfNecessary(WPXPropertyList &propList);
234 
238  shared_ptr<MWAWContentListenerInternal::State> _pushParsingState();
240  void _popParsingState();
241 
242 protected:
244  shared_ptr<MWAWContentListenerInternal::DocumentState> m_ds;
246  shared_ptr<MWAWContentListenerInternal::State> m_ps;
248  std::vector<shared_ptr<MWAWContentListenerInternal::State> > m_psStack;
252  WPXDocumentInterface *m_documentInterface;
253 
254 private:
257 };
258 
259 typedef shared_ptr<MWAWContentListener> MWAWContentListenerPtr;
260 
261 #endif
262 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Sat May 4 2013 11:47:11 for libmwaw by doxygen 1.8.3.1