Debian Codegraph @

src/lib/MWAWSpreadsheetListener.hxx

raw
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 /** \file MWAWSpreadsheetListener.hxx
35 * Defines MWAWSpreadsheetListener: the libmwaw spreadsheet processor listener
36 *
37 * \note this class is the only class which does the interface with
38 * the librevenge::RVNGSpreadsheetInterface
39 */
40 #ifndef MWAW_SPREADSHEET_LISTENER_H
41 #define MWAW_SPREADSHEET_LISTENER_H
42
43 #include <vector>
44
45 #include <librevenge/librevenge.h>
46
47 #include "libmwaw_internal.hxx"
48
49 #include "MWAWListener.hxx"
50
51 class MWAWCell;
52 class MWAWCellContent;
53 class MWAWChart;
54 class MWAWGraphicStyle;
55 class MWAWGraphicShape;
56 class MWAWTable;
57
58 namespace MWAWSpreadsheetListenerInternal
59 {
60 struct DocumentState;
61 struct State;
62 }
63
64 /** This class contents the main functions needed to create a spreadsheet processing Document */
65 class MWAWSpreadsheetListener final : public MWAWListener
66 {
67 public:
68 /** constructor */
69 MWAWSpreadsheetListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface);
70 /** simplified constructor (can be used for a embedded spreadsheet with one page).
71
72 \note the box coordinates must be given in point.*/
73 MWAWSpreadsheetListener(MWAWParserState &parserState, MWAWBox2f const &box, librevenge::RVNGSpreadsheetInterface *documentInterface);
74 /** destructor */
75 ~MWAWSpreadsheetListener() final;
76
77 /** returns the listener type */
78 Type getType() const final
79 {
80 return Spreadsheet;
81 }
82
83 /** sets the documents metadata */
84 void setDocumentMetaData(librevenge::RVNGPropertyList const &metadata) final;
85 /** sets the documents language */
86 void setDocumentLanguage(std::string const &locale) final;
87
88 /** starts the document */
89 void startDocument() final;
90 /** ends the document */
91 void endDocument(bool sendDelayedSubDoc=true) final;
92 /** returns true if a document is opened */
93 bool isDocumentStarted() const final;
94
95 /** function called to add a subdocument */
96 void handleSubDocument(MWAWSubDocumentPtr const &subDocument, libmwaw::SubDocumentType subDocumentType) final;
97 /** returns try if a subdocument is open */
98 bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const final;
99 /** tries to open a frame */
100 bool openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()) final;
101 /** tries to close a frame */
102 void closeFrame() final;
103 /** open a group (not implemented) */
104 bool openGroup(MWAWPosition const &pos) final;
105 /** close a group (not implemented) */
106 void closeGroup() final;
107
108 /** returns true if we can add text data */
109 bool canWriteText() const final;
110
111 // ------ page --------
112 /** returns true if a page is opened */
113 bool isPageSpanOpened() const final;
114 /** returns the current page span
115
116 \note this forces the opening of a new page if no page is opened.*/
117 MWAWPageSpan const &getPageSpan() final;
118
119 // ------ header/footer --------
120 /** insert a header */
121 bool insertHeader(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) final;
122 /** insert a footer */
123 bool insertFooter(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) final;
124 /** returns true if the header/footer is open */
125 bool isHeaderFooterOpened() const final;
126
127 // ------- sheet -----------------
128 /** opens a sheet
129
130 \note if defWidth is positive, add 1000 columns with size defWidth
131 */
132 void openSheet(std::vector<float> const &colWidth, librevenge::RVNGUnit unit,
133 std::vector<int> const &repeatColWidthNumber=std::vector<int>(), std::string const &name="");
134 /** closes this sheet */
135 void closeSheet();
136 /** open a row with given height ( if h < 0.0, set min-row-height = -h )*/
137 void openSheetRow(float h, librevenge::RVNGUnit unit, int numRepeated=1);
138 /** closes this row */
139 void closeSheetRow();
140 /** open a cell */
141 void openSheetCell(MWAWCell const &cell, MWAWCellContent const &content, int numRepeated=1);
142 /** close a cell */
143 void closeSheetCell();
144
145 // ------- chart -----------------
146 /** adds a chart in given position */
147 void insertChart(MWAWPosition const &pos, MWAWChart &chart,
148 MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
149
150 // ------ text data -----------
151
152 //! adds a basic character, ..
153 void insertChar(uint8_t character) final;
154 /** insert a character using the font converter to find the utf8
155 character */
156 void insertCharacter(unsigned char c) final;
157 /** insert a character using the font converter to find the utf8
158 character and if needed, input to read extra character.
159
160 \return the number of extra character read
161 */
162 int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1) final;
163 /** adds an unicode character.
164 * By convention if \a character=0xfffd(undef), no character is added */
165 void insertUnicode(uint32_t character) final;
166 //! adds a unicode string
167 void insertUnicodeString(librevenge::RVNGString const &str) final;
168
169 //! adds a tab
170 void insertTab() final;
171 //! adds an end of line ( by default an hard one)
172 void insertEOL(bool softBreak=false) final;
173
174 // ------ text format -----------
175 //! sets the font
176 void setFont(MWAWFont const &font) final;
177 //! returns the actual font
178 MWAWFont const &getFont() const final;
179
180 // ------ paragraph format -----------
181 //! returns true if a paragraph or a list is opened
182 bool isParagraphOpened() const final;
183 //! sets the paragraph
184 void setParagraph(MWAWParagraph const &paragraph) final;
185 //! returns the actual paragraph
186 MWAWParagraph const &getParagraph() const final;
187
188 // ------- fields ----------------
189 //! adds a field type
190 void insertField(MWAWField const &field) final;
191
192 // ------- link ----------------
193 //! open a link
194 void openLink(MWAWLink const &link) final;
195 //! close a link
196 void closeLink() final;
197
198 // ------- subdocument -----------------
199 /** insert a note */
200 void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument) final;
201
202 /** adds comment */
203 void insertComment(MWAWSubDocumentPtr &subDocument) final;
204
205 /** adds a picture with potential various representationin given position */
206 void insertPicture(MWAWPosition const &pos, MWAWEmbeddedObject const &picture,
207 MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()) final;
208 /** adds a shape picture in given position */
209 void insertShape(MWAWPosition const &pos, MWAWGraphicShape const &shape,
210 MWAWGraphicStyle const &style) final;
211 /** adds a textbox in given position */
212 void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr const &subDocument,
213 MWAWGraphicStyle const &frameStyle=MWAWGraphicStyle::emptyStyle()) final;
214
215 // ------- table -----------------
216 /** adds a table in given position */
217 void insertTable(MWAWPosition const &pos, MWAWTable &table, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
218 /** open a table */
219 void openTable(MWAWTable const &table) final;
220 /** closes this table */
221 void closeTable() final;
222 /** open a row with given height ( if h < 0.0, set min-row-height = -h )*/
223 void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false) final;
224 /** closes this row */
225 void closeTableRow() final;
226 /** open a cell */
227 void openTableCell(MWAWCell const &cell) final;
228 /** close a cell */
229 void closeTableCell() final;
230 /** add empty cell */
231 void addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span=MWAWVec2i(1,1)) final;
232
233 // ------- section ---------------
234 /** returns true if we can add open a section, add page break, ... */
235 bool canOpenSectionAddBreak() const final
236 {
237 return false;
238 }
239 //! returns true if a section is opened
240 bool isSectionOpened() const final
241 {
242 return false;
243 }
244 //! returns the actual section
245 MWAWSection const &getSection() const final;
246 //! open a section if possible
247 bool openSection(MWAWSection const &section) final;
248 //! close a section
249 bool closeSection() final;
250 //! inserts a break type: ColumBreak, PageBreak, ..
251 void insertBreak(BreakType breakType) final;
252
253 protected:
254 //! does open a new page (low level)
255 void _openPageSpan(bool sendHeaderFooters=true);
256 //! does close a page (low level)
257 void _closePageSpan();
258
259 void _startSubDocument();
260 void _endSubDocument();
261
262 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, MWAWPosition const &pos);
263
264 void _openParagraph();
265 void _closeParagraph();
266 void _resetParagraphState(const bool isListElement=false);
267
268 /** open a list level */
269 void _openListElement();
270 /** close a list level */
271 void _closeListElement();
272 /** update the list so that it corresponds to the actual level */
273 void _changeList();
274 /** low level: find a list id which corresponds to actual list and a change of level.
275
276 \note called when the list id is not set
277 */
278 int _getListId() const;
279
280 void _openSpan();
281 void _closeSpan();
282
283 void _flushText();
284 void _flushDeferredTabs();
285
286 /** creates a new parsing state (copy of the actual state)
287 *
288 * \return the old one */
289 std::shared_ptr<MWAWSpreadsheetListenerInternal::State> _pushParsingState();
290 //! resets the previous parsing state
291 void _popParsingState();
292
293 protected:
294 //! the main parse state
295 std::shared_ptr<MWAWSpreadsheetListenerInternal::DocumentState> m_ds;
296 //! the actual local parse state
297 std::shared_ptr<MWAWSpreadsheetListenerInternal::State> m_ps;
298 //! stack of local state
299 std::vector<std::shared_ptr<MWAWSpreadsheetListenerInternal::State> > m_psStack;
300 //! the parser state
301 MWAWParserState &m_parserState;
302 //! the document interface
303 librevenge::RVNGSpreadsheetInterface *m_documentInterface;
304
305 private:
306 //! copy constructor (unimplemented)
307 MWAWSpreadsheetListener(const MWAWSpreadsheetListener &);
308 //! operator= (unimplemented)
309 MWAWSpreadsheetListener &operator=(const MWAWSpreadsheetListener &);
310 };
311
312 #endif
313 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: