MWAWSpreadsheetListener.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 
00040 #ifndef MWAW_SPREADSHEET_LISTENER_H
00041 #define MWAW_SPREADSHEET_LISTENER_H
00042 
00043 #include <vector>
00044 
00045 #include <librevenge/librevenge.h>
00046 
00047 #include "libmwaw_internal.hxx"
00048 
00049 #include "MWAWListener.hxx"
00050 
00051 class MWAWCell;
00052 class MWAWCellContent;
00053 class MWAWChart;
00054 class MWAWGraphicStyle;
00055 class MWAWGraphicShape;
00056 class MWAWTable;
00057 
00058 namespace MWAWSpreadsheetListenerInternal
00059 {
00060 struct DocumentState;
00061 struct State;
00062 }
00063 
00065 class MWAWSpreadsheetListener : public MWAWListener
00066 {
00067 public:
00069   MWAWSpreadsheetListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface);
00073   MWAWSpreadsheetListener(MWAWParserState &parserState, MWAWBox2f const &box, librevenge::RVNGSpreadsheetInterface *documentInterface);
00075   virtual ~MWAWSpreadsheetListener();
00076 
00078   Type getType() const
00079   {
00080     return Spreadsheet;
00081   }
00082 
00084   void setDocumentLanguage(std::string locale);
00085 
00087   void startDocument();
00089   void endDocument(bool sendDelayedSubDoc=true);
00091   bool isDocumentStarted() const;
00092 
00094   void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
00096   bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
00098   bool openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00100   void closeFrame();
00101 
00103   bool canWriteText() const;
00104 
00105   // ------ page --------
00107   bool isPageSpanOpened() const;
00111   MWAWPageSpan const &getPageSpan();
00112 
00113   // ------ header/footer --------
00115   bool insertHeader(MWAWSubDocumentPtr subDocument, librevenge::RVNGPropertyList const &extras);
00117   bool insertFooter(MWAWSubDocumentPtr subDocument, librevenge::RVNGPropertyList const &extras);
00119   bool isHeaderFooterOpened() const;
00120 
00121   // ------- sheet -----------------
00123   void openSheet(std::vector<float> const &colWidth, librevenge::RVNGUnit unit, std::string const &name="");
00125   void closeSheet();
00127   void openSheetRow(float h, librevenge::RVNGUnit unit);
00129   void closeSheetRow();
00131   void openSheetCell(MWAWCell const &cell, MWAWCellContent const &content);
00133   void closeSheetCell();
00134 
00135   // ------- chart -----------------
00137   void insertChart(MWAWPosition const &pos, MWAWChart &chart,
00138                    MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00139 
00140   // ------ text data -----------
00141 
00143   void insertChar(uint8_t character);
00146   void insertCharacter(unsigned char c);
00152   int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
00155   void insertUnicode(uint32_t character);
00157   void insertUnicodeString(librevenge::RVNGString const &str);
00158 
00160   void insertTab();
00162   void insertEOL(bool softBreak=false);
00163 
00164   // ------ text format -----------
00166   void setFont(MWAWFont const &font);
00168   MWAWFont const &getFont() const;
00169 
00170   // ------ paragraph format -----------
00172   bool isParagraphOpened() const;
00174   void setParagraph(MWAWParagraph const &paragraph);
00176   MWAWParagraph const &getParagraph() const;
00177 
00178   // ------- fields ----------------
00180   void insertField(MWAWField const &field);
00181 
00182   // ------- link ----------------
00184   void openLink(MWAWLink const &link);
00186   void closeLink();
00187 
00188   // ------- subdocument -----------------
00190   void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument);
00191 
00193   void insertComment(MWAWSubDocumentPtr &subDocument);
00194 
00196   void insertPicture(MWAWPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
00197                      std::string type="image/pict", MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00199   void insertPicture(MWAWPosition const &pos, MWAWGraphicShape const &shape,
00200                      MWAWGraphicStyle const &style);
00202   void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument,
00203                      MWAWGraphicStyle const &frameStyle=MWAWGraphicStyle::emptyStyle());
00204 
00205   // ------- table -----------------
00207   void insertTable(MWAWPosition const &pos, MWAWTable &table, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00209   void openTable(MWAWTable const &table);
00211   void closeTable();
00213   void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
00215   void closeTableRow();
00217   void openTableCell(MWAWCell const &cell);
00219   void closeTableCell();
00221   void addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span=MWAWVec2i(1,1));
00222 
00223   // ------- section ---------------
00225   bool canOpenSectionAddBreak() const
00226   {
00227     return false;
00228   }
00230   bool isSectionOpened() const
00231   {
00232     return false;
00233   }
00235   MWAWSection const &getSection() const;
00237   bool openSection(MWAWSection const &section);
00239   bool closeSection();
00241   void insertBreak(BreakType breakType);
00242 
00243 protected:
00245   void _openPageSpan(bool sendHeaderFooters=true);
00247   void _closePageSpan();
00248 
00249   void _startSubDocument();
00250   void _endSubDocument();
00251 
00252   void _handleFrameParameters(librevenge::RVNGPropertyList &propList, MWAWPosition const &pos);
00253 
00254   void _openParagraph();
00255   void _closeParagraph();
00256   void _resetParagraphState(const bool isListElement=false);
00257 
00259   void _openListElement();
00261   void _closeListElement();
00263   void _changeList();
00268   int _getListId() const;
00269 
00270   void _openSpan();
00271   void _closeSpan();
00272 
00273   void _flushText();
00274   void _flushDeferredTabs();
00275 
00279   shared_ptr<MWAWSpreadsheetListenerInternal::State> _pushParsingState();
00281   void _popParsingState();
00282 
00283 protected:
00285   shared_ptr<MWAWSpreadsheetListenerInternal::DocumentState> m_ds;
00287   shared_ptr<MWAWSpreadsheetListenerInternal::State> m_ps;
00289   std::vector<shared_ptr<MWAWSpreadsheetListenerInternal::State> > m_psStack;
00291   MWAWParserState &m_parserState;
00293   librevenge::RVNGSpreadsheetInterface *m_documentInterface;
00294 
00295 private:
00297   MWAWSpreadsheetListener(const MWAWSpreadsheetListener &);
00299   MWAWSpreadsheetListener &operator=(const MWAWSpreadsheetListener &);
00300 };
00301 
00302 #endif
00303 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: