STOFFCell.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 /* libstaroffice
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 
00038 #ifndef STOFF_CELL_H
00039 #  define STOFF_CELL_H
00040 
00041 #include <string>
00042 #include <vector>
00043 
00044 #include "libstaroffice_internal.hxx"
00045 
00046 #include "STOFFEntry.hxx"
00047 #include "STOFFFont.hxx"
00048 #include "STOFFCellStyle.hxx"
00049 
00050 class STOFFTable;
00051 
00053 class STOFFCell
00054 {
00055 public:
00057   enum FormatType { F_TEXT, F_BOOLEAN, F_NUMBER, F_DATE, F_TIME, F_DATETIME, F_UNKNOWN };
00059   enum NumberType { F_NUMBER_CURRENCY, F_NUMBER_DECIMAL, F_NUMBER_FRACTION, F_NUMBER_GENERIC, F_NUMBER_SCIENTIFIC, F_NUMBER_PERCENT, F_NUMBER_UNKNOWN };
00061   struct Format {
00063     Format() : m_format(F_UNKNOWN), m_numberFormat(F_NUMBER_UNKNOWN)
00064     {
00065     }
00067     virtual ~Format();
00069     bool hasBasicFormat() const
00070     {
00071       return m_format==F_TEXT || m_format==F_UNKNOWN;
00072     }
00074     std::string getValueType() const;
00076     static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector);
00078     friend std::ostream &operator<<(std::ostream &o, Format const &format);
00079 
00081     FormatType m_format;
00083     NumberType m_numberFormat;
00084   };
00086   STOFFCell() : m_position(0,0),m_bdBox(),  m_bdSize(),
00087     m_format(), m_font(), m_cellStyle(), m_numberingStyle() { }
00088 
00090   virtual ~STOFFCell() {}
00091 
00093   void addTo(librevenge::RVNGPropertyList &propList) const;
00094 
00096   friend std::ostream &operator<<(std::ostream &o, STOFFCell const &cell);
00097 
00098   // interface with STOFFTable:
00099 
00104   virtual bool send(STOFFListenerPtr listener, STOFFTable &table);
00109   virtual bool sendContent(STOFFListenerPtr listener, STOFFTable &table);
00110 
00111   // position
00112 
00114   STOFFVec2i const &position() const
00115   {
00116     return m_position;
00117   }
00119   void setPosition(STOFFVec2i posi)
00120   {
00121     m_position = posi;
00122   }
00123 
00125   STOFFBox2f const &bdBox() const
00126   {
00127     return m_bdBox;
00128   }
00130   void setBdBox(STOFFBox2f box)
00131   {
00132     m_bdBox = box;
00133   }
00134 
00136   STOFFVec2f const &bdSize() const
00137   {
00138     return m_bdSize;
00139   }
00141   void setBdSize(STOFFVec2f sz)
00142   {
00143     m_bdSize = sz;
00144   }
00145 
00147   static std::string getCellName(STOFFVec2i const &pos, STOFFVec2b const &absolute);
00148 
00150   static std::string getColumnName(int col);
00151 
00152   // format
00153 
00155   Format const &getFormat() const
00156   {
00157     return m_format;
00158   }
00160   void setFormat(Format const &format)
00161   {
00162     m_format=format;
00163   }
00164 
00166   STOFFFont const &getFont() const
00167   {
00168     return m_font;
00169   }
00171   void setFont(STOFFFont const &font)
00172   {
00173     m_font=font;
00174   }
00175 
00177   STOFFCellStyle const &getCellStyle() const
00178   {
00179     return m_cellStyle;
00180   }
00182   STOFFCellStyle &getCellStyle()
00183   {
00184     return m_cellStyle;
00185   }
00187   void setCellStyle(STOFFCellStyle const &cellStyle)
00188   {
00189     m_cellStyle=cellStyle;
00190   }
00191 
00193   librevenge::RVNGPropertyList const &getNumberingStyle() const
00194   {
00195     return m_numberingStyle;
00196   }
00198   librevenge::RVNGPropertyList &getNumberingStyle()
00199   {
00200     return m_numberingStyle;
00201   }
00203   void setNumberingStyle(librevenge::RVNGPropertyList const &numberStyle)
00204   {
00205     m_numberingStyle=numberStyle;
00206   }
00207 protected:
00209   STOFFVec2i m_position;
00211   STOFFBox2f m_bdBox;
00213   STOFFVec2f m_bdSize;
00214 
00216   Format m_format;
00218   STOFFFont m_font;
00220   STOFFCellStyle m_cellStyle;
00222   librevenge::RVNGPropertyList m_numberingStyle;
00223 };
00224 
00226 class STOFFCellContent
00227 {
00228 public:
00230   struct FormulaInstruction {
00231     enum Type { F_None, F_Operator, F_Function, F_Cell, F_CellList, F_Index, F_Long, F_Double, F_Text };
00233     FormulaInstruction() : m_type(F_None), m_content(""), m_longValue(0), m_doubleValue(0), m_sheet(""),
00234       m_sheetId(-1), m_sheetIdRelative(false), m_extra("")
00235     {
00236       for (int i=0; i<2; ++i) {
00237         m_position[i]=STOFFVec2i(0,0);
00238         m_positionRelative[i]=STOFFVec2b(false,false);
00239       }
00240     }
00242     librevenge::RVNGPropertyList getPropertyList() const;
00244     friend std::ostream &operator<<(std::ostream &o, FormulaInstruction const &inst);
00246     Type m_type;
00248     librevenge::RVNGString m_content;
00250     long m_longValue;
00252     double m_doubleValue;
00254     STOFFVec2i m_position[2];
00256     STOFFVec2b m_positionRelative[2];
00258     librevenge::RVNGString m_sheet;
00260     int m_sheetId;
00262     bool m_sheetIdRelative;
00264     std::string m_extra;
00265   };
00266 
00268   enum Type { C_NONE, C_TEXT, C_TEXT_BASIC, C_NUMBER, C_FORMULA, C_UNKNOWN };
00270   STOFFCellContent() : m_contentType(C_UNKNOWN), m_value(0.0), m_valueSet(false), m_text(), m_formula() { }
00272   ~STOFFCellContent() {}
00274   friend std::ostream &operator<<(std::ostream &o, STOFFCellContent const &cell);
00275 
00277   bool empty() const
00278   {
00279     if (m_contentType == C_NUMBER || m_contentType == C_TEXT) return false;
00280     if (m_contentType == C_TEXT_BASIC && !m_text.empty()) return false;
00281     if (m_contentType == C_FORMULA && (m_formula.size() || isValueSet())) return false;
00282     return true;
00283   }
00285   void setValue(double value)
00286   {
00287     m_value = value;
00288     m_valueSet = true;
00289   }
00291   bool isValueSet() const
00292   {
00293     return m_valueSet;
00294   }
00296   bool hasText() const
00297   {
00298     return m_contentType == C_TEXT || !m_text.empty();
00299   }
00302   static bool double2Date(double val, int &Y, int &M, int &D);
00304   static bool double2Time(double val, int &H, int &M, int &S);
00306   static bool date2Double(int Y, int M, int D, double &val);
00308   Type m_contentType;
00310   double m_value;
00312   bool m_valueSet;
00314   std::vector<uint32_t> m_text;
00316   std::vector<FormulaInstruction> m_formula;
00317 };
00318 
00319 #endif
00320 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: