1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ 2 3 /* libstaroffice 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 34 /** \file STOFFSpreadsheetListener.hxx 35 * Defines STOFFSpreadsheetListener: the libstaroffice spreadsheet processor listener 36 * 37 * \note this class is the only class which does the interface with 38 * the librevenge::RVNGSpreadsheetInterface 39 */ 40 #ifndef STOFF_SPREADSHEET_LISTENER_H 41 #define STOFF_SPREADSHEET_LISTENER_H 42 43 #include <vector> 44 45 #include <librevenge/librevenge.h> 46 47 #include "libstaroffice_internal.hxx" 48 49 #include "STOFFListener.hxx" 50 51 class STOFFCell; 52 class STOFFCellContent; 53 class STOFFChart; 54 class STOFFGraphicStyle; 55 class STOFFTable; 56 57 namespace STOFFSpreadsheetListenerInternal 58 { 59 struct DocumentState; 60 struct State; 61 } 62 63 /** This class contents the main functions needed to create a spreadsheet processing Document */ 64 class STOFFSpreadsheetListener final : public STOFFListener 65 { 66 public: 67 /** constructor */ 68 STOFFSpreadsheetListener(STOFFListManagerPtr &listManager, std::vector<STOFFPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface); 69 /** destructor */ 70 ~STOFFSpreadsheetListener() final; 71 72 /** returns the listener type */ getType() const73 Type getType() const final 74 { 75 return Spreadsheet; 76 } 77 78 /** sets the document language */ 79 void setDocumentLanguage(std::string locale) final; 80 /** sets the document meta data */ 81 void setDocumentMetaData(const librevenge::RVNGPropertyList &list) final; 82 83 /** starts the document */ 84 void startDocument() final; 85 /** ends the document */ 86 void endDocument(bool sendDelayedSubDoc=true) final; 87 /** returns true if a document is opened */ 88 bool isDocumentStarted() const final; 89 90 /** function called to add a subdocument */ 91 void handleSubDocument(STOFFSubDocumentPtr subDocument, libstoff::SubDocumentType subDocumentType) final; 92 /** returns try if a subdocument is open */ 93 bool isSubDocumentOpened(libstoff::SubDocumentType &subdocType) const final; 94 /** tries to open a frame */ 95 bool openFrame(STOFFFrameStyle const &frame, STOFFGraphicStyle const &style=STOFFGraphicStyle()) final; 96 /** tries to close a frame */ 97 void closeFrame() final; 98 /** open a group (not implemented) */ 99 bool openGroup(STOFFFrameStyle const &frame) final; 100 /** close a group (not implemented) */ 101 void closeGroup() final; 102 103 /** returns true if we can add text data */ 104 bool canWriteText() const final; 105 106 // ------ page -------- 107 /** returns true if a page is opened */ 108 bool isPageSpanOpened() const final; 109 /** returns the current page span 110 111 \note this forces the opening of a new page if no page is opened.*/ 112 STOFFPageSpan const &getPageSpan() final; 113 114 // ------ header/footer -------- 115 /** open a header (interaction with STOFFPageSpan which fills the parameters for openHeader) */ 116 bool openHeader(librevenge::RVNGPropertyList const &extras) final; 117 /** open a footer (interaction with STOFFPageSpan which fills the parameters for openFooter) */ 118 bool openFooter(librevenge::RVNGPropertyList const &extras) final; 119 /** close a header */ 120 bool closeHeader() final; 121 /** close a footer */ 122 bool closeFooter() final; 123 /** insert a header */ 124 bool insertHeaderRegion(STOFFSubDocumentPtr subDocument, librevenge::RVNGString const &which) final; 125 /** insert a footer */ 126 bool insertFooterRegion(STOFFSubDocumentPtr subDocument, librevenge::RVNGString const &which) final; 127 /** returns true if the header/footer is open */ 128 bool isHeaderFooterOpened() const final; 129 130 // ------- sheet ----------------- 131 /** open a sheet*/ 132 void openSheet(std::vector<float> const &colWidth, librevenge::RVNGUnit unit, 133 std::vector<int> const &repeatColWidthNumber=std::vector<int>(), librevenge::RVNGString 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(STOFFCell const &cell, STOFFCellContent 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(STOFFFrameStyle const &frame, STOFFChart &chart, STOFFGraphicStyle const &style=STOFFGraphicStyle()); 148 149 // ------ text data ----------- 150 151 //! adds a basic character, .. 152 void insertChar(uint8_t character) final; 153 /** adds an unicode character. 154 * By convention if \a character=0xfffd(undef), no character is added */ 155 void insertUnicode(uint32_t character) final; 156 //! adds a unicode string 157 void insertUnicodeString(librevenge::RVNGString const &str) final; 158 159 //! adds a tab 160 void insertTab() final; 161 //! adds an end of line ( by default an hard one) 162 void insertEOL(bool softBreak=false) final; 163 164 // ------ text format ----------- 165 //! sets the font 166 void setFont(STOFFFont const &font) final; 167 //! returns the actual font 168 STOFFFont const &getFont() const final; 169 170 // ------ paragraph format ----------- 171 //! returns true if a paragraph or a list is opened 172 bool isParagraphOpened() const final; 173 //! sets the paragraph 174 void setParagraph(STOFFParagraph const ¶graph) final; 175 //! returns the actual paragraph 176 STOFFParagraph const &getParagraph() const final; 177 178 // ------ style definition ----------- 179 /** defines a font styles */ 180 void defineStyle(STOFFFont const &style) final; 181 /** check if a font style with a display name is already defined */ 182 bool isFontStyleDefined(librevenge::RVNGString const &name) const final; 183 /** defines a graphic styles */ 184 void defineStyle(STOFFGraphicStyle const &style) final; 185 /** check if a graphic style with a display name is already defined */ 186 bool isGraphicStyleDefined(librevenge::RVNGString const &name) const final; 187 /** defines a paragraph styles */ 188 void defineStyle(STOFFParagraph const &style) final; 189 /** check if a paragraph style with a display name is already defined */ 190 bool isParagraphStyleDefined(librevenge::RVNGString const &name) const final; 191 192 // ------- fields ---------------- 193 //! adds a field type 194 void insertField(STOFFField const &field) final; 195 196 // ------- link ---------------- 197 //! open a link 198 void openLink(STOFFLink const &link) final; 199 //! close a link 200 void closeLink() final; 201 202 // ------- subdocument ----------------- 203 /** insert a note */ 204 void insertNote(STOFFNote const ¬e, STOFFSubDocumentPtr &subDocument) final; 205 /** adds comment */ 206 void insertComment(STOFFSubDocumentPtr &subDocument, librevenge::RVNGString const &creator="", librevenge::RVNGString const &date="") final; 207 208 /** adds a picture with potential various representationin given position */ 209 void insertPicture(STOFFFrameStyle const &frame, STOFFEmbeddedObject const &picture, 210 STOFFGraphicStyle const &style=STOFFGraphicStyle()) final; 211 /** adds a equation given a position */ 212 void insertEquation(STOFFFrameStyle const &frame, librevenge::RVNGString const &equation, 213 STOFFGraphicStyle const &style=STOFFGraphicStyle()) final; 214 /** adds a shape picture in given position */ 215 void insertShape(STOFFFrameStyle const &frame, STOFFGraphicShape const &shape, STOFFGraphicStyle const &style) final; 216 /** adds a textbox in given position */ 217 void insertTextBox(STOFFFrameStyle const &frame, STOFFSubDocumentPtr subDocument, 218 STOFFGraphicStyle const &frameStyle=STOFFGraphicStyle()) final; 219 // ------- table ----------------- 220 /** open a table */ 221 void openTable(STOFFTable const &table) final; 222 /** closes this table */ 223 void closeTable() final; 224 /** open a row with given height ( if h < 0.0, set min-row-height = -h )*/ 225 void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false) final; 226 /** closes this row */ 227 void closeTableRow() final; 228 /** open a cell */ 229 void openTableCell(STOFFCell const &cell) final; 230 /** close a cell */ 231 void closeTableCell() final; 232 /** add covered cell */ 233 void addCoveredTableCell(STOFFVec2i const &pos) final; 234 /** add empty cell */ 235 void addEmptyTableCell(STOFFVec2i const &pos, STOFFVec2i span=STOFFVec2i(1,1)) final; 236 237 // ------- section --------------- 238 /** returns true if we can add open a section, add page break, ... */ canOpenSectionAddBreak() const239 bool canOpenSectionAddBreak() const final 240 { 241 return false; 242 } 243 //! returns true if a section is opened isSectionOpened() const244 bool isSectionOpened() const final 245 { 246 return false; 247 } 248 //! returns the actual section 249 STOFFSection const &getSection() const final; 250 //! open a section if possible 251 bool openSection(STOFFSection const §ion) final; 252 //! close a section 253 bool closeSection() final; 254 //! inserts a break type: ColumBreak, PageBreak, .. 255 void insertBreak(BreakType breakType) final; 256 257 protected: 258 //! does open a new page (low level) 259 void _openPageSpan(bool sendHeaderFooters=true); 260 //! does close a page (low level) 261 void _closePageSpan(); 262 263 void _startSubDocument(); 264 void _endSubDocument(); 265 266 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, STOFFFrameStyle const &frame); 267 268 void _openParagraph(); 269 void _closeParagraph(); 270 void _resetParagraphState(const bool isListElement=false); 271 272 /** open a list level */ 273 void _openListElement(); 274 /** close a list level */ 275 void _closeListElement(); 276 /** update the list so that it corresponds to the actual level */ 277 void _changeList(); 278 /** low level: find a list id which corresponds to actual list and a change of level. 279 280 \note called when the list id is not set 281 */ 282 int _getListId() const; 283 284 void _openSpan(); 285 void _closeSpan(); 286 287 void _flushText(); 288 void _flushDeferredTabs(); 289 290 /** creates a new parsing state (copy of the actual state) 291 * 292 * \return the old one */ 293 std::shared_ptr<STOFFSpreadsheetListenerInternal::State> _pushParsingState(); 294 //! resets the previous parsing state 295 void _popParsingState(); 296 297 protected: 298 //! the main parse state 299 std::shared_ptr<STOFFSpreadsheetListenerInternal::DocumentState> m_ds; 300 //! the actual local parse state 301 std::shared_ptr<STOFFSpreadsheetListenerInternal::State> m_ps; 302 //! stack of local state 303 std::vector<std::shared_ptr<STOFFSpreadsheetListenerInternal::State> > m_psStack; 304 //! the document interface 305 librevenge::RVNGSpreadsheetInterface *m_documentInterface; 306 307 private: 308 //! copy constructor (unimplemented) 309 STOFFSpreadsheetListener(const STOFFSpreadsheetListener &); 310 //! operator= (unimplemented) 311 STOFFSpreadsheetListener &operator=(const STOFFSpreadsheetListener &); 312 }; 313 314 #endif 315 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: 316