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;
56 class MWAWSection;
58 
59 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
60 typedef shared_ptr<MWAWSubDocument> MWAWSubDocumentPtr;
61 
62 namespace MWAWContentListenerInternal
63 {
64 struct DocumentState;
65 struct State;
66 }
67 
69 {
70 public:
72 
74  MWAWContentListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
76  virtual ~MWAWContentListener();
77 
79  void setDocumentLanguage(std::string locale);
80 
82  void startDocument();
84  void endDocument(bool sendDelayedSubDoc=true);
85 
87  void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
89  bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
90 
91  // ------ page --------
93  bool isPageSpanOpened() const;
97  MWAWPageSpan const &getPageSpan();
98 
99  // ------ header/footer --------
101  bool insertHeader(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
103  bool insertFooter(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
105  bool isHeaderFooterOpened() const;
106 
107  // ------ text data -----------
108 
110  void insertChar(uint8_t character);
113  void insertCharacter(unsigned char c);
119  int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
122  void insertUnicode(uint32_t character);
124  void insertUnicodeString(WPXString const &str);
125 
127  void insertTab();
129  void insertEOL(bool softBreak=false);
131  void insertBreak(BreakType breakType);
132 
133  // ------ text format -----------
135  void setFont(MWAWFont const &font);
137  MWAWFont const &getFont() const;
138 
139  // ------ paragraph format -----------
141  bool isParagraphOpened() const;
143  void setParagraph(MWAWParagraph const &paragraph);
145  MWAWParagraph const &getParagraph() const;
146 
147  // ------- fields ----------------
149  void insertField(MWAWField const&field);
150 
151  // ------- subdocument -----------------
153  void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument);
154 
156  void insertComment(MWAWSubDocumentPtr &subDocument);
157 
159  void insertPicture(MWAWPosition const &pos, const WPXBinaryData &binaryData,
160  std::string type="image/pict",
161  WPXPropertyList frameExtras=WPXPropertyList());
163  void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument,
164  WPXPropertyList frameExtras=WPXPropertyList(),
165  WPXPropertyList textboxExtras=WPXPropertyList());
166 
167  // ------- table -----------------
169  void openTable(std::vector<float> const &colWidth, WPXUnit unit,
170  WPXPropertyList tableExtras=WPXPropertyList());
172  void closeTable();
174  void openTableRow(float h, WPXUnit unit, bool headerRow=false);
176  void closeTableRow();
180  void openTableCell(MWAWCell const &cell, WPXPropertyList const &extras);
182  void closeTableCell();
184  void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
185 
186  // ------- section ---------------
188  bool isSectionOpened() const;
190  MWAWSection const &getSection() const;
192  bool openSection(MWAWSection const &section);
194  bool closeSection();
195 
196 protected:
197  void _openSection();
198  void _closeSection();
199 
200  void _openPageSpan(bool sendHeaderFooters=true);
201  void _closePageSpan();
202 
203  void _startSubDocument();
204  void _endSubDocument();
205 
206  void _handleFrameParameters( WPXPropertyList &propList, MWAWPosition const &pos);
207  bool openFrame(MWAWPosition const &pos, WPXPropertyList extras=WPXPropertyList());
208  void closeFrame();
209 
210 
211  void _openParagraph();
212  void _closeParagraph();
213  void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
214  void _resetParagraphState(const bool isListElement=false);
215 
217  void _openListElement();
219  void _closeListElement();
221  void _changeList();
226  int _getListId() const;
227 
228  void _openSpan();
229  void _closeSpan();
230 
231  void _flushText();
232  void _flushDeferredTabs();
233 
234  void _insertBreakIfNecessary(WPXPropertyList &propList);
235 
239  shared_ptr<MWAWContentListenerInternal::State> _pushParsingState();
241  void _popParsingState();
242 
243 protected:
245  shared_ptr<MWAWContentListenerInternal::DocumentState> m_ds;
247  shared_ptr<MWAWContentListenerInternal::State> m_ps;
249  std::vector<shared_ptr<MWAWContentListenerInternal::State> > m_psStack;
253  WPXDocumentInterface *m_documentInterface;
254 
255 private:
258 };
259 
260 typedef shared_ptr<MWAWContentListener> MWAWContentListenerPtr;
261 
262 #endif
263 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Wed May 22 2013 18:12:38 for libmwaw by doxygen 1.8.1.2