MWAWContentListener.hxx
Go to the documentation of this file.
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 (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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 
40 #ifndef MWAW_CONTENT_LISTENER_H
41 #define MWAW_CONTENT_LISTENER_H
42 
43 #include <vector>
44 
45 #include <libwpd/libwpd.h>
46 
47 #include "libmwaw_internal.hxx"
48 
49 #include "MWAWListener.hxx"
50 
51 class MWAWCell;
52 class MWAWGraphicStyle;
53 class MWAWGraphicShape;
54 class MWAWTable;
55 
56 namespace MWAWContentListenerInternal
57 {
58 struct DocumentState;
59 struct State;
60 }
61 
64 {
65 public:
67  MWAWContentListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
69  virtual ~MWAWContentListener();
70 
72  void setDocumentLanguage(std::string locale);
73 
75  void startDocument();
77  void endDocument(bool sendDelayedSubDoc=true);
79  bool isDocumentStarted() const;
80 
82  void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
84  bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
85 
87  bool canWriteText() const {
89  }
90 
91  // ------ page --------
93  bool isPageSpanOpened() const;
97  MWAWPageSpan const &getPageSpan();
98 
99  // ------ header/footer --------
101  bool insertHeader(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
103  bool insertFooter(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
105  bool isHeaderFooterOpened() const;
106 
107  // ------ text data -----------
108 
110  void insertChar(uint8_t character);
113  void insertCharacter(unsigned char c);
119  int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
122  void insertUnicode(uint32_t character);
124  void insertUnicodeString(WPXString const &str);
125 
127  void insertTab();
129  void insertEOL(bool softBreak=false);
130 
131  // ------ text format -----------
133  void setFont(MWAWFont const &font);
135  MWAWFont const &getFont() const;
136 
137  // ------ paragraph format -----------
139  bool isParagraphOpened() const;
141  void setParagraph(MWAWParagraph const &paragraph);
143  MWAWParagraph const &getParagraph() const;
144 
145  // ------- fields ----------------
147  void insertField(MWAWField const &field);
148 
149  // ------- subdocument -----------------
151  void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument);
152 
154  void insertComment(MWAWSubDocumentPtr &subDocument);
155 
157  void insertPicture(MWAWPosition const &pos, const WPXBinaryData &binaryData,
158  std::string type="image/pict",
159  WPXPropertyList frameExtras=WPXPropertyList());
161  void insertPicture(MWAWPosition const &pos, MWAWGraphicShape const &shape,
162  MWAWGraphicStyle const &style);
164  void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument,
165  WPXPropertyList frameExtras=WPXPropertyList(),
166  WPXPropertyList textboxExtras=WPXPropertyList());
167 
168  // ------- table -----------------
170  void openTable(MWAWTable const &table, WPXPropertyList tableExtras=WPXPropertyList());
172  void closeTable();
174  void openTableRow(float h, WPXUnit unit, bool headerRow=false);
176  void closeTableRow();
178  void openTableCell(MWAWCell const &cell);
180  void closeTableCell();
182  void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
183 
184  // ------- section ---------------
186  bool canOpenSectionAddBreak() const;
188  bool isSectionOpened() const;
190  MWAWSection const &getSection() const;
192  bool openSection(MWAWSection const &section);
194  bool closeSection();
196  void insertBreak(BreakType breakType);
197 
198 protected:
200  void _openSection();
202  void _closeSection();
204  void _openPageSpan(bool sendHeaderFooters=true);
206  void _closePageSpan();
207 
208  void _startSubDocument();
209  void _endSubDocument();
210 
211  void _handleFrameParameters( WPXPropertyList &propList, MWAWPosition const &pos);
212  bool openFrame(MWAWPosition const &pos, WPXPropertyList extras=WPXPropertyList());
213  void closeFrame();
214 
215 
216  void _openParagraph();
217  void _closeParagraph();
218  void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
219  void _resetParagraphState(const bool isListElement=false);
220 
222  void _openListElement();
224  void _closeListElement();
226  void _changeList();
231  int _getListId() const;
232 
233  void _openSpan();
234  void _closeSpan();
235 
236  void _flushText();
237  void _flushDeferredTabs();
238 
239  void _insertBreakIfNecessary(WPXPropertyList &propList);
240 
244  shared_ptr<MWAWContentListenerInternal::State> _pushParsingState();
246  void _popParsingState();
247 
248 protected:
250  shared_ptr<MWAWContentListenerInternal::DocumentState> m_ds;
252  shared_ptr<MWAWContentListenerInternal::State> m_ps;
254  std::vector<shared_ptr<MWAWContentListenerInternal::State> > m_psStack;
258  WPXDocumentInterface *m_documentInterface;
259 
260 private:
265 };
266 
267 #endif
268 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
void _openParagraph()
Definition: MWAWContentListener.cxx:722
bool isHeaderFooterOpened() const
returns true if the header/footer is open
Definition: MWAWContentListener.cxx:601
bool isParagraphOpened() const
returns true if a paragraph or a list is opened
Definition: MWAWContentListener.cxx:392
void closeTable()
closes this table
Definition: MWAWContentListener.cxx:1550
void _closeListElement()
close a list level
Definition: MWAWContentListener.cxx:825
bool isDocumentStarted() const
returns true if a document is opened
Definition: MWAWContentListener.cxx:479
shared_ptr< MWAWContentListenerInternal::DocumentState > m_ds
the main parse state
Definition: MWAWContentListener.hxx:250
void insertCharacter(unsigned char c)
insert a character using the font converter to find the utf8 character
Definition: MWAWContentListener.cxx:221
MWAWParagraph const & getParagraph() const
returns the actual paragraph
Definition: MWAWContentListener.cxx:404
MWAWPageSpan const & getPageSpan()
returns the current page span
Definition: MWAWContentListener.cxx:535
void insertField(MWAWField const &field)
adds a field type
Definition: MWAWContentListener.cxx:412
A class which defines the page properties.
Definition: MWAWPageSpan.hxx:95
bool isSectionOpened() const
returns true if a section is opened
Definition: MWAWContentListener.cxx:635
bool closeSection()
close a section
Definition: MWAWContentListener.cxx:666
bool openSection(MWAWSection const &section)
open a section if possible
Definition: MWAWContentListener.cxx:650
void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType)
function called to add a subdocument
Definition: MWAWContentListener.cxx:1426
bool insertHeader(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras)
insert a header
Definition: MWAWContentListener.cxx:606
void _openSection()
does open a section (low level)
Definition: MWAWContentListener.cxx:681
void openTableRow(float h, WPXUnit unit, bool headerRow=false)
open a row with given height ( if h < 0.0, set min-row-height = -h )
Definition: MWAWContentListener.cxx:1564
void insertUnicode(uint32_t character)
adds an unicode character.
Definition: MWAWContentListener.cxx:263
void insertEOL(bool softBreak=false)
adds an end of line ( by default an hard one)
Definition: MWAWContentListener.cxx:280
a structure used to define a picture style
Definition: MWAWGraphicStyle.hxx:47
void _flushText()
Definition: MWAWContentListener.cxx:977
SubDocumentType
Definition: libmwaw_internal.hxx:162
void insertComment(MWAWSubDocumentPtr &subDocument)
adds comment
Definition: MWAWContentListener.cxx:1062
a class used to recreate the table structure using cell informations, ....
Definition: MWAWTable.hxx:53
void _insertBreakIfNecessary(WPXPropertyList &propList)
Definition: MWAWContentListener.cxx:352
void startDocument()
starts the document
Definition: MWAWContentListener.cxx:484
int _getListId() const
low level: find a list id which corresponds to actual list and a change of level. ...
Definition: MWAWContentListener.cxx:841
void insertTab()
adds a tab
Definition: MWAWContentListener.cxx:297
virtual ~MWAWContentListener()
destructor
Definition: MWAWContentListener.cxx:203
void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false)
Definition: MWAWContentListener.cxx:780
a structure used to define a cell and its format
Definition: MWAWCell.hxx:51
Vec2< int > Vec2i
Vec2 of int.
Definition: libmwaw_internal.hxx:592
shared_ptr< MWAWSubDocument > MWAWSubDocumentPtr
a smart pointer of MWAWSubDocument
Definition: libmwaw_internal.hxx:358
WPXDocumentInterface * m_documentInterface
the document interface
Definition: MWAWContentListener.hxx:258
void _handleFrameParameters(WPXPropertyList &propList, MWAWPosition const &pos)
Definition: MWAWContentListener.cxx:1226
bool canOpenSectionAddBreak() const
returns true if we can add open a section, add page break, ...
Definition: MWAWContentListener.cxx:645
shared_ptr< MWAWContentListenerInternal::State > m_ps
the actual local parse state
Definition: MWAWContentListener.hxx:252
bool canWriteText() const
returns true if we can add text data
Definition: MWAWContentListener.hxx:87
void closeTableRow()
closes this row
Definition: MWAWContentListener.cxx:1585
void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1, 1))
add empty cell
Definition: MWAWContentListener.cxx:1595
bool isPageSpanOpened() const
returns true if a page is opened
Definition: MWAWContentListener.cxx:530
a class to define the parser state
Definition: MWAWParser.hxx:51
BreakType
the different break type
Definition: MWAWListener.hxx:52
void insertUnicodeString(WPXString const &str)
adds a unicode string
Definition: MWAWContentListener.cxx:273
void endDocument(bool sendDelayedSubDoc=true)
ends the document
Definition: MWAWContentListener.cxx:499
void _openPageSpan(bool sendHeaderFooters=true)
does open a new page (low level)
Definition: MWAWContentListener.cxx:543
void insertBreak(BreakType breakType)
inserts a break type: ColumBreak, PageBreak, ..
Definition: MWAWContentListener.cxx:308
bool insertFooter(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras)
insert a footer
Definition: MWAWContentListener.cxx:619
void _resetParagraphState(const bool isListElement=false)
Definition: MWAWContentListener.cxx:772
void openTableCell(MWAWCell const &cell)
open a cell
Definition: MWAWContentListener.cxx:1614
void _closeSection()
does close a section (low level)
Definition: MWAWContentListener.cxx:702
void _closeParagraph()
Definition: MWAWContentListener.cxx:751
void _openSpan()
Definition: MWAWContentListener.cxx:921
void _closeSpan()
Definition: MWAWContentListener.cxx:945
void _flushDeferredTabs()
Definition: MWAWContentListener.cxx:958
void openTable(MWAWTable const &table, WPXPropertyList tableExtras=WPXPropertyList())
open a table
Definition: MWAWContentListener.cxx:1525
void _openListElement()
open a list level
Definition: MWAWContentListener.cxx:793
void setParagraph(MWAWParagraph const &paragraph)
sets the paragraph
Definition: MWAWContentListener.cxx:397
a class which stores section properties
Definition: MWAWSection.hxx:45
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:348
void setFont(MWAWFont const &font)
sets the font
Definition: MWAWContentListener.cxx:371
a structure used to define a picture shape
Definition: MWAWGraphicShape.hxx:46
void _changeList()
update the list so that it corresponds to the actual level
Definition: MWAWContentListener.cxx:858
void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument, WPXPropertyList frameExtras=WPXPropertyList(), WPXPropertyList textboxExtras=WPXPropertyList())
adds a textbox in given position
Definition: MWAWContentListener.cxx:1087
MWAWFont const & getFont() const
returns the actual font
Definition: MWAWContentListener.cxx:387
class to store the paragraph properties
Definition: MWAWParagraph.hxx:82
void _endSubDocument()
Definition: MWAWContentListener.cxx:1511
void insertChar(uint8_t character)
adds a basic character, ..
Definition: MWAWContentListener.cxx:210
bool openFrame(MWAWPosition const &pos, WPXPropertyList extras=WPXPropertyList())
Definition: MWAWContentListener.cxx:1159
a field
Definition: libmwaw_internal.hxx:286
void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument)
insert a note
Definition: MWAWContentListener.cxx:1007
void _popParsingState()
resets the previous parsing state
Definition: MWAWContentListener.cxx:1665
bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const
returns try if a subdocument is open
Definition: MWAWContentListener.cxx:1497
MWAWParserState & m_parserState
the parser state
Definition: MWAWContentListener.hxx:256
a note
Definition: libmwaw_internal.hxx:304
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: MWAWPosition.hxx:47
This class contains a virtual interface to all listener.
Definition: MWAWListener.hxx:46
MWAWContentListener & operator=(const MWAWContentListener &)
operator= (unimplemented)
void _startSubDocument()
Definition: MWAWContentListener.cxx:1505
This class contents the main functions needed to create a Word processing Document.
Definition: MWAWContentListener.hxx:63
void _closePageSpan()
does close a page (low level)
Definition: MWAWContentListener.cxx:586
void closeFrame()
Definition: MWAWContentListener.cxx:1215
shared_ptr< MWAWContentListenerInternal::State > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition: MWAWContentListener.cxx:1651
void insertPicture(MWAWPosition const &pos, const WPXBinaryData &binaryData, std::string type="image/pict", WPXPropertyList frameExtras=WPXPropertyList())
adds a picture in given position
Definition: MWAWContentListener.cxx:1134
std::vector< shared_ptr< MWAWContentListenerInternal::State > > m_psStack
stack of local state
Definition: MWAWContentListener.hxx:254
void closeTableCell()
close a cell
Definition: MWAWContentListener.cxx:1631
void setDocumentLanguage(std::string locale)
sets the documents language
Definition: MWAWContentListener.cxx:473
MWAWSection const & getSection() const
returns the actual section
Definition: MWAWContentListener.cxx:640
MWAWContentListener(MWAWParserState &parserState, std::vector< MWAWPageSpan > const &pageList, WPXDocumentInterface *documentInterface)
constructor
Definition: MWAWContentListener.cxx:197

Generated on Fri May 23 2014 22:12:55 for libmwaw by doxygen 1.8.7