MsWksDocument.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 /* libmwaw
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 MS_WKS_DOCUMENT
00035 #  define MS_WKS_DOCUMENT
00036 
00037 #include <string>
00038 #include <map>
00039 #include <vector>
00040 
00041 #include <librevenge/librevenge.h>
00042 
00043 #include "libmwaw_internal.hxx"
00044 
00045 #include "MWAWDebug.hxx"
00046 #include "MWAWCell.hxx"
00047 
00048 namespace MsWksDocumentInternal
00049 {
00050 struct State;
00051 
00052 class SubDocument;
00053 }
00054 
00055 class MsWksParser;
00056 class MsWksDBParser;
00057 class MsWksDRParser;
00058 class MsWksSSParser;
00059 class MsWks4Zone;
00060 
00061 class MsWksGraph;
00062 class MsWks3Text;
00063 class MsWks4Text;
00064 
00067 class MsWksDocument
00068 {
00069   friend class MsWksDocumentInternal::SubDocument;
00070   friend class MsWksParser;
00071   friend class MsWks4Zone;
00072   friend class MsWksDBParser;
00073   friend class MsWksDRParser;
00074   friend class MsWksSSParser;
00075 public:
00077   enum ZoneType { Z_MAIN, Z_HEADER, Z_FOOTER, Z_NONE };
00079   struct Zone {
00081     Zone(ZoneType type=Z_NONE, int zoneId=-1) : m_type(type), m_zoneId(zoneId), m_textId(-1) {}
00083     ZoneType m_type;
00085     int m_zoneId;
00087     int m_textId;
00088   };
00089 
00090 public:
00091 
00093   MsWksDocument(MWAWInputStreamPtr input, MWAWParser &parser);
00095   virtual ~MsWksDocument();
00096 
00098   int version() const;
00100   void setVersion(int vers);
00102   MWAWDocument::Kind getKind() const;
00104   void setKind(MWAWDocument::Kind kind);
00105 
00107   MWAWInputStreamPtr &getInput()
00108   {
00109     return m_input;
00110   }
00112   MWAWParser &getMainParser()
00113   {
00114     return *m_parser;
00115   }
00117   shared_ptr<MsWksGraph> getGraphParser()
00118   {
00119     return m_graphParser;
00120   }
00122   shared_ptr<MsWks3Text> getTextParser3();
00124   shared_ptr<MsWks4Text> getTextParser4();
00126   libmwaw::DebugFile &ascii()
00127   {
00128     return m_asciiFile;
00129   }
00130 
00131   //
00132   // read some v3 structure
00133   //
00134 
00136   bool checkHeader3(MWAWHeader *header, bool strict=false);
00138   long getLengthOfFileHeader3() const;
00140   bool readPrintInfo();
00142   bool readDocumentInfo(long sz=-1);
00144   bool readZone(Zone &zone);
00146   bool readGroupHeaderFooter(bool header, int check);
00147 
00148   //
00149   // read some ole structures
00150   //
00151 
00153   bool createOLEZones(MWAWInputStreamPtr input);
00155   std::vector<std::string> const &getUnparsedOLEZones() const;
00156   //
00157   // utilities functions
00158   //
00159 
00161   bool hasHeader() const;
00163   bool hasFooter() const;
00165   float getHeaderFooterHeight(bool header) const;
00167   void getPageSpanList(std::vector<MWAWPageSpan> &pagesList, int &numPages);
00169   static bool getColor(int id, MWAWColor &col, int vers);
00171   static std::vector<MWAWColor> const &getPalette(int vers);
00172 
00174   std::multimap<int, Zone> &getTypeZoneMap();
00176   Zone getZone(ZoneType type) const;
00178   int getNewZoneId() const;
00180   std::multimap<std::string, MWAWEntry> &getEntryMap();
00181 
00182   // general interface
00183 
00185   void sendZone(int zoneType);
00186 
00187   // interface with the text parser
00188 
00190   void newPage(int page, bool softBreak=false);
00192   void sendFootnoteContent(int noteId);
00194   void sendFootnote(int id);
00196   void sendText(int id);
00197 
00198   // interface with the graph parser
00199 
00201   void sendOLE(int id, MWAWPosition const &pos, MWAWGraphicStyle const &style);
00203   void sendRBIL(int id, MWAWVec2i const &sz);
00205   void sendTextbox(MWAWEntry const &entry, std::string const &frame);
00206 
00207 protected:
00208   //
00209   // spreadsheet/database function
00210   //
00211 
00213   bool readCellInFormula(MWAWCellContent::FormulaInstruction &instr, bool is2D);
00215   bool readDBString(long endPos, std::string &res);
00217   bool readDBNumber(long endPos, double &res, bool &isNan, std::string &str);
00218   /* reads a formula */
00219   bool readFormula(long endPos, MWAWCellContent &content, std::string &extra);
00220 
00221 protected:
00222 
00223   //
00224   // low level
00225   //
00227   void initAsciiFile(std::string const &name);
00228 
00229 private:
00230   MsWksDocument(MsWksDocument const &orig);
00231   MsWksDocument &operator=(MsWksDocument const &orig);
00232 
00233   //
00234   // data
00235   //
00236 
00237 protected:
00239   shared_ptr<MsWksDocumentInternal::State> m_state;
00240 public:
00242   shared_ptr<MWAWParserState> m_parserState;
00243 
00244 protected:
00246   MWAWParser *m_parser;
00248   MsWksDocument *m_parentDocument;
00250   MWAWInputStreamPtr m_input;
00252   libmwaw::DebugFile m_asciiFile;
00253 
00255   shared_ptr<MsWksGraph> m_graphParser;
00257   shared_ptr<MsWks3Text> m_textParser3;
00259   shared_ptr<MsWks4Text> m_textParser4;
00260 
00262   typedef void (MWAWParser::* NewPage)(int page, bool softBreak);
00263 
00265   NewPage m_newPage;
00266 };
00267 #endif
00268 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: