| 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 ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 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_LISTENER_H |
| 35 |
#define MWAW_LISTENER_H |
| 36 |
|
| 37 |
#include <vector> |
| 38 |
|
| 39 |
#include <librevenge/librevenge.h> |
| 40 |
|
| 41 |
#include "libmwaw_internal.hxx" |
| 42 |
|
| 43 |
#include "MWAWGraphicStyle.hxx" |
| 44 |
|
| 45 |
class MWAWCell; |
| 46 |
class MWAWTable; |
| 47 |
|
| 48 |
/** This class contains a virtual interface to all listener */ |
| 49 |
class MWAWListener |
| 50 |
{ |
| 51 |
public: |
| 52 |
//! destructor |
| 53 |
virtual ~MWAWListener(); |
| 54 |
|
| 55 |
//! the listener type |
| 56 |
enum Type { Graphic, Presentation, Spreadsheet, Text }; |
| 57 |
/** the different break type */ |
| 58 |
enum BreakType { PageBreak=0, SoftPageBreak, ColumnBreak }; |
| 59 |
|
| 60 |
//------- generic accessor --- |
| 61 |
/** returns the listener type */ |
| 62 |
virtual Type getType() const = 0; |
| 63 |
/** returns true if we can add text data */ |
| 64 |
virtual bool canWriteText() const =0; |
| 65 |
|
| 66 |
// ------ main document ------- |
| 67 |
/** sets the documents metadata */ |
| 68 |
virtual void setDocumentMetaData(librevenge::RVNGPropertyList const &metadata) = 0; |
| 69 |
/** sets the documents language */ |
| 70 |
virtual void setDocumentLanguage(std::string const &locale) = 0; |
| 71 |
/** starts the document */ |
| 72 |
virtual void startDocument() = 0; |
| 73 |
/** returns true if a document is opened */ |
| 74 |
virtual bool isDocumentStarted() const =0; |
| 75 |
/** ends the document */ |
| 76 |
virtual void endDocument(bool sendDelayedSubDoc=true) = 0; |
| 77 |
|
| 78 |
// ------ page -------- |
| 79 |
/** returns true if a page is opened */ |
| 80 |
virtual bool isPageSpanOpened() const = 0; |
| 81 |
/** returns the current page span |
| 82 |
|
| 83 |
\note this forces the opening of a new page if no page is opened.*/ |
| 84 |
virtual MWAWPageSpan const &getPageSpan() = 0; |
| 85 |
|
| 86 |
// ------ header/footer -------- |
| 87 |
/** insert a header (interaction with MWAWPageSpan which fills the parameters for openHeader) */ |
| 88 |
virtual bool insertHeader(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) = 0; |
| 89 |
/** insert a footer (interaction with MWAWPageSpan which fills the parameters for openFooter) */ |
| 90 |
virtual bool insertFooter(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) = 0; |
| 91 |
/** returns true if the header/footer is open */ |
| 92 |
virtual bool isHeaderFooterOpened() const = 0; |
| 93 |
|
| 94 |
// ------ text data ----------- |
| 95 |
//! adds a basic character, .. |
| 96 |
virtual void insertChar(uint8_t character)=0; |
| 97 |
/** insert a character using the font converter to find the utf8 |
| 98 |
character */ |
| 99 |
virtual void insertCharacter(unsigned char c)=0; |
| 100 |
/** insert a character using the font converter to find the utf8 |
| 101 |
character and if needed, input to read extra character. |
| 102 |
|
| 103 |
\return the number of extra character read |
| 104 |
*/ |
| 105 |
virtual int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1)=0; |
| 106 |
/** adds an unicode character. |
| 107 |
* By convention if \a character=0xfffd(undef), no character is added */ |
| 108 |
virtual void insertUnicode(uint32_t character)=0; |
| 109 |
//! adds a unicode string |
| 110 |
virtual void insertUnicodeString(librevenge::RVNGString const &str)=0; |
| 111 |
|
| 112 |
//! adds a tab |
| 113 |
virtual void insertTab()=0; |
| 114 |
//! adds an end of line ( by default an hard one) |
| 115 |
virtual void insertEOL(bool softBreak=false)=0; |
| 116 |
|
| 117 |
// ------ text format ----------- |
| 118 |
//! sets the font |
| 119 |
virtual void setFont(MWAWFont const &font)=0; |
| 120 |
//! returns the actual font |
| 121 |
virtual MWAWFont const &getFont() const=0; |
| 122 |
|
| 123 |
// ------ paragraph format ----------- |
| 124 |
//! returns true if a paragraph or a list is opened |
| 125 |
virtual bool isParagraphOpened() const=0; |
| 126 |
//! sets the paragraph |
| 127 |
virtual void setParagraph(MWAWParagraph const ¶graph)=0; |
| 128 |
//! returns the actual paragraph |
| 129 |
virtual MWAWParagraph const &getParagraph() const=0; |
| 130 |
|
| 131 |
// ------- fields ---------------- |
| 132 |
//! adds a field type |
| 133 |
virtual void insertField(MWAWField const &field)=0; |
| 134 |
|
| 135 |
// ------- link ---------------- |
| 136 |
|
| 137 |
//! open a link |
| 138 |
virtual void openLink(MWAWLink const &link)=0; |
| 139 |
//! close a link |
| 140 |
virtual void closeLink()=0; |
| 141 |
|
| 142 |
// ------- table ----------------- |
| 143 |
/** open a table*/ |
| 144 |
virtual void openTable(MWAWTable const &table) = 0; |
| 145 |
/** closes this table */ |
| 146 |
virtual void closeTable() = 0; |
| 147 |
/** open a row with given height ( if h < 0.0, set min-row-height = -h )*/ |
| 148 |
virtual void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false) = 0; |
| 149 |
/** closes this row */ |
| 150 |
virtual void closeTableRow() = 0; |
| 151 |
/** open a cell */ |
| 152 |
virtual void openTableCell(MWAWCell const &cell) = 0; |
| 153 |
/** close a cell */ |
| 154 |
virtual void closeTableCell() = 0; |
| 155 |
/** add empty cell */ |
| 156 |
virtual void addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span=MWAWVec2i(1,1)) = 0; |
| 157 |
|
| 158 |
// ------- section --------------- |
| 159 |
/** returns true if we can add open a section, add page break, ... */ |
| 160 |
virtual bool canOpenSectionAddBreak() const =0; |
| 161 |
//! returns true if a section is opened |
| 162 |
virtual bool isSectionOpened() const=0; |
| 163 |
//! returns the actual section |
| 164 |
virtual MWAWSection const &getSection() const=0; |
| 165 |
//! open a section if possible |
| 166 |
virtual bool openSection(MWAWSection const §ion)=0; |
| 167 |
//! close a section |
| 168 |
virtual bool closeSection()=0; |
| 169 |
//! inserts a break type: ColumBreak, PageBreak, .. |
| 170 |
virtual void insertBreak(BreakType breakType)=0; |
| 171 |
|
| 172 |
// ------- subdocument --------------- |
| 173 |
/** insert a note */ |
| 174 |
virtual void insertNote(MWAWNote const ¬e, MWAWSubDocumentPtr &subDocument)=0; |
| 175 |
/** adds comment */ |
| 176 |
virtual void insertComment(MWAWSubDocumentPtr &subDocument) = 0; |
| 177 |
/** adds a picture with various representationin given position. |
| 178 |
\note by default only send the first picture*/ |
| 179 |
virtual void insertPicture(MWAWPosition const &pos, MWAWEmbeddedObject const &picture, |
| 180 |
MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle())=0; |
| 181 |
/** adds a shape picture in given position */ |
| 182 |
virtual void insertShape(MWAWPosition const &pos, MWAWGraphicShape const &shape, |
| 183 |
MWAWGraphicStyle const &style) = 0; |
| 184 |
/** adds a textbox in given position */ |
| 185 |
virtual void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr const &subDocument, |
| 186 |
MWAWGraphicStyle const &frameStyle=MWAWGraphicStyle::emptyStyle()) = 0; |
| 187 |
/** adds a textbox in given position */ |
| 188 |
virtual void insertTextBoxInShape(MWAWPosition const &pos, MWAWSubDocumentPtr const &subDocument, |
| 189 |
MWAWGraphicShape const &/*shape*/, |
| 190 |
MWAWGraphicStyle const &frameStyle=MWAWGraphicStyle::emptyStyle()) |
| 191 |
{ |
| 192 |
static bool first=true; |
| 193 |
if (first) { |
| 194 |
MWAW_DEBUG_MSG(("MWAWListener::insertTextBoxInShape: umimplemented, revert to basic insertTextBox\n")); |
| 195 |
first=false; |
| 196 |
} |
| 197 |
insertTextBox(pos, subDocument, frameStyle); |
| 198 |
} |
| 199 |
/** low level: tries to open a frame */ |
| 200 |
virtual bool openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()) = 0; |
| 201 |
/** low level: tries to close the last opened frame */ |
| 202 |
virtual void closeFrame() = 0; |
| 203 |
/** low level: tries to open a group */ |
| 204 |
virtual bool openGroup(MWAWPosition const &pos) = 0; |
| 205 |
/** low level: tries to close the last opened group */ |
| 206 |
virtual void closeGroup() = 0; |
| 207 |
/** low level: function called to add a subdocument */ |
| 208 |
virtual void handleSubDocument(MWAWSubDocumentPtr const &subDocument, libmwaw::SubDocumentType subDocumentType) = 0; |
| 209 |
/** returns true if a subdocument is open */ |
| 210 |
virtual bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const = 0; |
| 211 |
}; |
| 212 |
|
| 213 |
#endif |
| 214 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |