MWAWContentListener.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 #ifndef MWAW_CONTENT_LISTENER_H
00035 #define MWAW_CONTENT_LISTENER_H
00036 
00037 #include <vector>
00038 
00039 #include <libwpd/libwpd.h>
00040 
00041 #include "libmwaw_internal.hxx"
00042 
00043 #include "MWAWListener.hxx"
00044 
00045 class MWAWCell;
00046 class MWAWGraphicStyle;
00047 class MWAWGraphicShape;
00048 class MWAWTable;
00049 
00050 namespace MWAWContentListenerInternal
00051 {
00052 struct DocumentState;
00053 struct State;
00054 }
00055 
00057 class MWAWContentListener : public MWAWListener
00058 {
00059 public:
00061   MWAWContentListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
00063   virtual ~MWAWContentListener();
00064 
00066   void setDocumentLanguage(std::string locale);
00067 
00069   void startDocument();
00071   void endDocument(bool sendDelayedSubDoc=true);
00073   bool isDocumentStarted() const;
00074 
00076   void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
00078   bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
00079 
00081   bool canWriteText() const {
00082     return MWAWContentListener::isDocumentStarted();
00083   }
00084 
00085   // ------ page --------
00087   bool isPageSpanOpened() const;
00091   MWAWPageSpan const &getPageSpan();
00092 
00093   // ------ header/footer --------
00095   bool insertHeader(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
00097   bool insertFooter(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
00099   bool isHeaderFooterOpened() const;
00100 
00101   // ------ text data -----------
00102 
00104   void insertChar(uint8_t character);
00107   void insertCharacter(unsigned char c);
00113   int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
00116   void insertUnicode(uint32_t character);
00118   void insertUnicodeString(WPXString const &str);
00119 
00121   void insertTab();
00123   void insertEOL(bool softBreak=false);
00124 
00125   // ------ text format -----------
00127   void setFont(MWAWFont const &font);
00129   MWAWFont const &getFont() const;
00130 
00131   // ------ paragraph format -----------
00133   bool isParagraphOpened() const;
00135   void setParagraph(MWAWParagraph const &paragraph);
00137   MWAWParagraph const &getParagraph() const;
00138 
00139   // ------- fields ----------------
00141   void insertField(MWAWField const &field);
00142 
00143   // ------- subdocument -----------------
00145   void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument);
00146 
00148   void insertComment(MWAWSubDocumentPtr &subDocument);
00149 
00151   void insertPicture(MWAWPosition const &pos, const WPXBinaryData &binaryData,
00152                      std::string type="image/pict",
00153                      WPXPropertyList frameExtras=WPXPropertyList());
00155   void insertPicture(MWAWPosition const &pos, MWAWGraphicShape const &shape,
00156                      MWAWGraphicStyle const &style);
00158   void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument,
00159                      WPXPropertyList frameExtras=WPXPropertyList(),
00160                      WPXPropertyList textboxExtras=WPXPropertyList());
00161 
00162   // ------- table -----------------
00164   void openTable(MWAWTable const &table, WPXPropertyList tableExtras=WPXPropertyList());
00166   void closeTable();
00168   void openTableRow(float h, WPXUnit unit, bool headerRow=false);
00170   void closeTableRow();
00172   void openTableCell(MWAWCell const &cell);
00174   void closeTableCell();
00176   void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
00177 
00178   // ------- section ---------------
00180   bool canOpenSectionAddBreak() const;
00182   bool isSectionOpened() const;
00184   MWAWSection const &getSection() const;
00186   bool openSection(MWAWSection const &section);
00188   bool closeSection();
00190   void insertBreak(BreakType breakType);
00191 
00192 protected:
00193   void _openSection();
00194   void _closeSection();
00195 
00196   void _openPageSpan(bool sendHeaderFooters=true);
00197   void _closePageSpan();
00198 
00199   void _startSubDocument();
00200   void _endSubDocument();
00201 
00202   void _handleFrameParameters( WPXPropertyList &propList, MWAWPosition const &pos);
00203   bool openFrame(MWAWPosition const &pos, WPXPropertyList extras=WPXPropertyList());
00204   void closeFrame();
00205 
00206 
00207   void _openParagraph();
00208   void _closeParagraph();
00209   void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
00210   void _resetParagraphState(const bool isListElement=false);
00211 
00213   void _openListElement();
00215   void _closeListElement();
00217   void _changeList();
00222   int _getListId() const;
00223 
00224   void _openSpan();
00225   void _closeSpan();
00226 
00227   void _flushText();
00228   void _flushDeferredTabs();
00229 
00230   void _insertBreakIfNecessary(WPXPropertyList &propList);
00231 
00235   shared_ptr<MWAWContentListenerInternal::State> _pushParsingState();
00237   void _popParsingState();
00238 
00239 protected:
00241   shared_ptr<MWAWContentListenerInternal::DocumentState> m_ds;
00243   shared_ptr<MWAWContentListenerInternal::State> m_ps;
00245   std::vector<shared_ptr<MWAWContentListenerInternal::State> > m_psStack;
00247   MWAWParserState &m_parserState;
00249   WPXDocumentInterface *m_documentInterface;
00250 
00251 private:
00252   MWAWContentListener(const MWAWContentListener &);
00253   MWAWContentListener &operator=(const MWAWContentListener &);
00254 };
00255 
00256 #endif
00257 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: