WPSContentListener.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwps
00003  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Major Contributor(s):
00010  * Copyright (C) 2006, 2007 Andrew Ziem
00011  * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00012  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
00013  * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
00014  *
00015  * For minor contributions see the git repository.
00016  *
00017  * Alternatively, the contents of this file may be used under the terms
00018  * of the GNU Lesser General Public License Version 2.1 or later
00019  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00020  * applicable instead of those above.
00021  *
00022  * For further information visit http://libwps.sourceforge.net
00023  */
00024 
00025 #ifndef WPSCONTENTLISTENER_H
00026 #define WPSCONTENTLISTENER_H
00027 
00028 #include <vector>
00029 
00030 #include <librevenge/librevenge.h>
00031 
00032 #include "libwps_internal.h"
00033 
00034 #include "WPSListener.h"
00035 
00036 class WPSList;
00037 class WPSPageSpan;
00038 struct WPSParagraph;
00039 struct WPSTabStop;
00040 
00041 struct WPSContentParsingState;
00042 struct WPSDocumentParsingState;
00043 
00044 class WPSContentListener : public WPSListener
00045 {
00046 public:
00047         WPSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGTextInterface *documentInterface);
00048         virtual ~WPSContentListener();
00049 
00050         void setDocumentLanguage(int lcid);
00051 
00052         void startDocument();
00053         void endDocument();
00054         void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
00055         bool isHeaderFooterOpened() const;
00056 
00057         // ------ text data -----------
00058 
00060         void insertCharacter(uint8_t character);
00064         void insertUnicode(uint32_t character);
00066         void insertUnicodeString(librevenge::RVNGString const &str);
00067 
00068         void insertTab();
00069         void insertEOL(bool softBreak=false);
00070         void insertBreak(const uint8_t breakType);
00071 
00072         // ------ text format -----------
00074         void setFont(const WPSFont &font);
00076         WPSFont const &getFont() const;
00077 
00078         // ------ paragraph format -----------
00080         bool isParagraphOpened() const;
00082         void setParagraph(const WPSParagraph &para);
00084         WPSParagraph const &getParagraph() const;
00085 
00086         // ------ list format -----------
00088         void setCurrentList(shared_ptr<WPSList> list);
00090         shared_ptr<WPSList> getCurrentList() const;
00091 
00092         // ------- fields ----------------
00094         void insertField(FieldType type);
00096         void insertDateTimeField(char const *format);
00097 
00098         // ------- subdocument -----------------
00100         enum NoteType { FOOTNOTE, ENDNOTE };
00102         void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument);
00104         void insertLabelNote(const NoteType noteType, librevenge::RVNGString const &label, WPSSubDocumentPtr &subDocument);
00106         void insertComment(WPSSubDocumentPtr &subDocument);
00107 
00109         void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
00110                            std::string type="image/pict",
00111                            librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
00113         void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
00114                            librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
00115 
00116 
00117         // ------- table -----------------
00119         void openTable(std::vector<float> const &colWidth, librevenge::RVNGUnit unit);
00121         void closeTable();
00123         void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
00125         void closeTableRow();
00129         void openTableCell(WPSCell const &cell, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList());
00131         void closeTableCell();
00133         void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
00134 
00135         // ------- section ---------------
00137         bool isSectionOpened() const;
00139         int getSectionNumColumns() const;
00141         bool openSection(std::vector<int> colsWidth=std::vector<int>(), librevenge::RVNGUnit unit=librevenge::RVNG_INCH);
00143         bool closeSection();
00144 
00145 protected:
00146         void _openSection();
00147         void _closeSection();
00148 
00149         void _openPageSpan();
00150         void _closePageSpan();
00151         void _updatePageSpanDependent(bool set);
00152 
00153         void _startSubDocument();
00154         void _endSubDocument();
00155 
00156         void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos);
00157         bool _openFrame(WPSPosition const &pos, librevenge::RVNGPropertyList extras=librevenge::RVNGPropertyList());
00158         void _closeFrame();
00159 
00160         void _openParagraph();
00161         void _closeParagraph();
00162         void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
00163         void _resetParagraphState(const bool isListElement=false);
00164 
00165         void _openListElement();
00166         void _closeListElement();
00167         void _changeList();
00168 
00169         void _openSpan();
00170         void _closeSpan();
00171 
00172         void _flushText();
00173         void _flushDeferredTabs();
00174 
00175         void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
00176 
00180         shared_ptr<WPSContentParsingState> _pushParsingState();
00182         void _popParsingState();
00183 
00184 protected:
00185         shared_ptr<WPSDocumentParsingState> m_ds; // main parse state
00186         shared_ptr<WPSContentParsingState> m_ps; // parse state
00187         std::vector<shared_ptr<WPSContentParsingState> > m_psStack;
00188         librevenge::RVNGTextInterface *m_documentInterface;
00189 
00190 private:
00191         WPSContentListener(const WPSContentListener &);
00192         WPSContentListener &operator=(const WPSContentListener &);
00193 };
00194 
00195 #endif
00196 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */