STOFFListener.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 /* libstaroffice
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 STOFF_LISTENER_H
00035 #define STOFF_LISTENER_H
00036 
00037 #include <vector>
00038 
00039 #include <librevenge/librevenge.h>
00040 
00041 #include "libstaroffice_internal.hxx"
00042 
00043 #include "STOFFGraphicStyle.hxx"
00044 #include "STOFFPosition.hxx"
00045 
00046 class STOFFCell;
00047 class STOFFTable;
00048 
00050 class STOFFListener
00051 {
00052 public:
00054   virtual ~STOFFListener();
00055 
00057   enum Type { Graphic, Presentation, Spreadsheet, Text };
00059   enum BreakType { PageBreak=0, SoftPageBreak, ColumnBreak };
00060 
00061   //------- generic accessor ---
00063   virtual Type getType() const = 0;
00065   virtual bool canWriteText() const =0;
00067   STOFFListManagerPtr getListManager() const
00068   {
00069     return m_listManager;
00070   }
00071   // ------ main document -------
00073   virtual void setDocumentLanguage(std::string locale) = 0;
00075   virtual void setDocumentMetaData(const librevenge::RVNGPropertyList &list) = 0;
00077   virtual void startDocument() = 0;
00079   virtual bool isDocumentStarted() const =0;
00081   virtual void endDocument(bool sendDelayedSubDoc=true) = 0;
00082 
00083   // ------ page --------
00085   virtual bool isPageSpanOpened() const = 0;
00089   virtual STOFFPageSpan const &getPageSpan() = 0;
00090 
00091   // ------ header/footer --------
00093   virtual bool openHeader(librevenge::RVNGPropertyList const &extras) = 0;
00095   virtual bool openFooter(librevenge::RVNGPropertyList const &extras) = 0;
00097   virtual bool closeHeader() = 0;
00099   virtual bool closeFooter() = 0;
00101   virtual bool insertHeaderRegion(STOFFSubDocumentPtr subDocument, librevenge::RVNGString const &which) = 0;
00103   virtual bool insertFooterRegion(STOFFSubDocumentPtr subDocument, librevenge::RVNGString const &which) = 0;
00105   virtual bool isHeaderFooterOpened() const = 0;
00106 
00107   // ------ text data -----------
00109   virtual void insertChar(uint8_t character)=0;
00112   virtual void insertUnicode(uint32_t character)=0;
00114   virtual void insertUnicodeList(std::vector<uint32_t> const &list)
00115   {
00116     if (list.empty() || !canWriteText())
00117       return;
00118     for (size_t i=0; i<list.size(); ++i) {
00119       if (list[i]==0x9) insertTab();
00120       else if (list[i]==0xa || list[i]==0xc) insertEOL(); // checkme: use softBreak ?
00121       else insertUnicode(list[i]);
00122     }
00123   }
00125   virtual void insertUnicodeString(librevenge::RVNGString const &str)=0;
00126 
00128   virtual void insertTab()=0;
00130   virtual void insertEOL(bool softBreak=false)=0;
00131 
00132   // ------ text format -----------
00134   virtual void setFont(STOFFFont const &font)=0;
00136   virtual STOFFFont const &getFont() const=0;
00137 
00138   // ------ paragraph format -----------
00140   virtual bool isParagraphOpened() const=0;
00142   virtual void setParagraph(STOFFParagraph const &paragraph)=0;
00144   virtual STOFFParagraph const &getParagraph() const=0;
00145 
00146   // ------ style definition -----------
00148   virtual void defineStyle(STOFFFont const &style) = 0;
00150   virtual bool isFontStyleDefined(librevenge::RVNGString const &name) const = 0;
00152   virtual void defineStyle(STOFFGraphicStyle const &style) = 0;
00154   virtual bool isGraphicStyleDefined(librevenge::RVNGString const &name) const = 0;
00156   virtual void defineStyle(STOFFParagraph const &style) = 0;
00158   virtual bool isParagraphStyleDefined(librevenge::RVNGString const &name) const = 0;
00159   // ------- fields ----------------
00161   virtual void insertField(STOFFField const &field)=0;
00162 
00163   // ------- link ----------------
00164 
00166   virtual void openLink(STOFFLink const &link)=0;
00168   virtual void closeLink()=0;
00169 
00170   // ------- table -----------------
00172   virtual void openTable(STOFFTable const &table) = 0;
00174   virtual void closeTable() = 0;
00176   virtual void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false) = 0;
00178   virtual void closeTableRow() = 0;
00180   virtual void openTableCell(STOFFCell const &cell) = 0;
00182   virtual void closeTableCell() = 0;
00184   virtual void addEmptyTableCell(STOFFVec2i const &pos, STOFFVec2i span=STOFFVec2i(1,1)) = 0;
00185 
00186   // ------- section ---------------
00188   virtual bool canOpenSectionAddBreak() const =0;
00190   virtual bool isSectionOpened() const=0;
00192   virtual STOFFSection const &getSection() const=0;
00194   virtual bool openSection(STOFFSection const &section)=0;
00196   virtual bool closeSection()=0;
00198   virtual void insertBreak(BreakType breakType)=0;
00199 
00200   // ------- subdocument ---------------
00202   virtual void insertNote(STOFFNote const &note, STOFFSubDocumentPtr &subDocument)=0;
00204   virtual void insertComment(STOFFSubDocumentPtr &subDocument, librevenge::RVNGString const &creator="", librevenge::RVNGString const &date="") = 0;
00207   virtual void insertPicture(STOFFPosition const &pos, STOFFEmbeddedObject const &picture,
00208                              STOFFGraphicStyle const &style=STOFFGraphicStyle())=0;
00210   virtual void insertShape(STOFFGraphicShape const &shape, STOFFGraphicStyle const &style, STOFFPosition const &pos) = 0;
00212   virtual void insertTextBox(STOFFPosition const &pos, STOFFSubDocumentPtr subDocument,
00213                              STOFFGraphicStyle const &frameStyle=STOFFGraphicStyle()) = 0;
00214 #if 0
00215 
00216   virtual void insertTextBoxInShape(STOFFPosition const &pos, STOFFSubDocumentPtr subDocument,
00217                                     STOFFGraphicShape const &/*shape*/,
00218                                     STOFFGraphicStyle const &frameStyle=STOFFGraphicStyle())
00219   {
00220     static bool first=true;
00221     if (first) {
00222       STOFF_DEBUG_MSG(("STOFFListener::insertTextBoxInShape: umimplemented, revert to basic insertTextBox\n"));
00223       first=false;
00224     }
00225     insertTextBox(pos, subDocument, frameStyle);
00226   }
00227 #endif
00228 
00229   virtual bool openFrame(STOFFPosition const &pos, STOFFGraphicStyle const &style=STOFFGraphicStyle()) = 0;
00231   virtual void closeFrame() = 0;
00233   virtual bool openGroup(STOFFPosition const &pos) = 0;
00235   virtual void closeGroup() = 0;
00237   virtual void handleSubDocument(STOFFSubDocumentPtr subDocument, libstoff::SubDocumentType subDocumentType) = 0;
00239   virtual bool isSubDocumentOpened(libstoff::SubDocumentType &subdocType) const = 0;
00240 
00241 protected:
00243   explicit STOFFListener(STOFFListManagerPtr listManager);
00245   STOFFListManagerPtr m_listManager;
00246 };
00247 
00248 #endif
00249 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: