ClarisWksDbaseContent.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 /*
00035  * The main database content used by Claris Works parser to store spreedsheet/Databese
00036  *
00037  */
00038 #ifndef CLARIS_WKS_DBASE_CONTENT
00039 #  define CLARIS_WKS_DBASE_CONTENT
00040 
00041 #include <iostream>
00042 #include <map>
00043 #include <vector>
00044 
00045 #include "libmwaw_internal.hxx"
00046 
00047 #include "MWAWCell.hxx"
00048 #include "MWAWEntry.hxx"
00049 #include "MWAWFont.hxx"
00050 
00051 #include "ClarisWksStyleManager.hxx"
00052 
00053 class ClarisWksDocument;
00054 
00056 class ClarisWksDbaseContent
00057 {
00058 public:
00059   struct Record;
00060 
00062   ClarisWksDbaseContent(ClarisWksDocument &document, bool spreadsheet);
00064   ~ClarisWksDbaseContent();
00066   bool readContent();
00067 
00069   bool getExtrema(MWAWVec2i &min, MWAWVec2i &max) const;
00071   bool getRecordList(std::vector<int> &list) const;
00072 
00074   bool get(MWAWVec2i const &pos, Record &data) const;
00076   bool send(MWAWVec2i const &pos);
00078   void setDatabaseFormats(std::vector<ClarisWksStyleManager::CellFormat> const &format);
00080   struct Record {
00082     Record() : m_style(-1), m_format(), m_hAlign(MWAWCell::HALIGN_DEFAULT), m_fileFormat(0),
00083       m_content(), m_valueType(MWAWCellContent::C_UNKNOWN), m_hasNaNValue(false), m_backgroundColor(MWAWColor::white()), m_font(3,9), m_borders(0)
00084     {
00085     }
00087     void updateFormulaCells(MWAWVec2i const &removeDelta);
00089     int m_style;
00091     MWAWCell::Format m_format;
00093     MWAWCell::HorizontalAlignment m_hAlign;
00095     int m_fileFormat;
00097     MWAWCellContent m_content;
00099     MWAWCellContent::Type m_valueType;
00101     bool m_hasNaNValue;
00103     MWAWColor m_backgroundColor;
00105     MWAWFont m_font;
00107     int m_borders;
00108   };
00109 protected:
00111   struct Column {
00113     Column() : m_idRecordMap()
00114     {
00115     }
00117     std::map<int,Record> m_idRecordMap;
00118   };
00119 
00121   bool readColumnList();
00123   bool readColumn(int c);
00125   bool readRecordList(MWAWVec2i const &where, Column &col);
00127   bool readRecordSS(MWAWVec2i const &where, long pos, Record &record);
00129   bool readRecordSSV1(MWAWVec2i const &where, long pos, Record &record);
00131   bool readRecordDB(MWAWVec2i const &where, long pos, Record &record);
00132 
00134   void send(double val, bool isNotaNumber, ClarisWksStyleManager::CellFormat const &format);
00135 
00136   //
00137   // low level
00138   //
00139 
00141   bool readCellInFormula(MWAWVec2i const &pos, MWAWCellContent::FormulaInstruction &instr);
00143   bool readString(long endPos, std::string &res);
00145   bool readNumber(long endPos, double &res, bool &isNan);
00147   bool readFormula(MWAWVec2i const &cPos, long endPos,
00148                    std::vector<MWAWCellContent::FormulaInstruction> &formula, std::string &error);
00149 
00151   int m_version;
00153   bool m_isSpreadsheet;
00154 
00156   ClarisWksDocument &m_document;
00158   MWAWParserStatePtr m_parserState;
00159 
00161   std::map<int, Column> m_idColumnMap;
00163   std::vector<ClarisWksStyleManager::CellFormat> m_dbFormatList;
00164 };
00165 #endif
00166 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
00167 
00168