MWAWCell.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 /* Define some classes used to store a Cell
00035  */
00036 
00037 #ifndef MWAW_CELL_H
00038 #  define MWAW_CELL_H
00039 
00040 #include <string>
00041 #include <vector>
00042 
00043 #include "libmwaw_internal.hxx"
00044 
00045 class WPXPropertyList;
00046 
00047 class MWAWTable;
00048 
00050 class MWAWCell
00051 {
00052 public:
00056   enum HorizontalAlignment { HALIGN_LEFT, HALIGN_RIGHT, HALIGN_CENTER,
00057                              HALIGN_FULL, HALIGN_DEFAULT
00058                            };
00059 
00062   enum VerticalAlignment { VALIGN_TOP, VALIGN_CENTER, VALIGN_BOTTOM, VALIGN_DEFAULT };
00063 
00065   enum ExtraLine { E_None, E_Line1, E_Line2, E_Cross };
00066 
00068   MWAWCell() : m_position(0,0), m_numberCellSpanned(1,1), m_bdBox(),  m_bdSize(),
00069     m_hAlign(HALIGN_DEFAULT), m_vAlign(VALIGN_DEFAULT), m_bordersList(),
00070     m_backgroundColor(MWAWColor::white()), m_protected(false),
00071     m_extraLine(E_None), m_extraLineType() { }
00072 
00074   virtual ~MWAWCell() {}
00075 
00077   void addTo(WPXPropertyList &propList) const;
00078 
00080   friend std::ostream &operator<<(std::ostream &o, MWAWCell const &cell);
00081 
00082   // interface with MWAWTable:
00083 
00088   virtual bool send(MWAWContentListenerPtr listener, MWAWTable &table);
00093   virtual bool sendContent(MWAWContentListenerPtr listener, MWAWTable &table);
00094 
00095   // position
00096 
00098   Vec2i const &position() const {
00099     return m_position;
00100   }
00102   void setPosition(Vec2i posi) {
00103     m_position = posi;
00104   }
00105 
00107   Vec2i const &numSpannedCells() const {
00108     return m_numberCellSpanned;
00109   }
00111   void setNumSpannedCells(Vec2i numSpanned) {
00112     m_numberCellSpanned=numSpanned;
00113   }
00114 
00116   Box2f const &bdBox() const {
00117     return m_bdBox;
00118   }
00120   void setBdBox(Box2f box) {
00121     m_bdBox = box;
00122   }
00123 
00125   Vec2f const &bdSize() const {
00126     return m_bdSize;
00127   }
00129   void setBdSize(Vec2f sz) {
00130     m_bdSize = sz;
00131   }
00132 
00134   static std::string getCellName(Vec2i const &pos, Vec2b const &absolute);
00135 
00137   static std::string getColumnName(int col);
00138 
00139   // format
00140 
00142   bool isProtected() const {
00143     return m_protected;
00144   }
00146   void setProtected(bool fl) {
00147     m_protected = fl;
00148   }
00149 
00151   HorizontalAlignment hAlignement() const {
00152     return m_hAlign;
00153   }
00155   void setHAlignement(HorizontalAlignment align) {
00156     m_hAlign = align;
00157   }
00158 
00160   VerticalAlignment vAlignement() const {
00161     return m_vAlign;
00162   }
00164   void setVAlignement(VerticalAlignment align) {
00165     m_vAlign = align;
00166   }
00167 
00169   bool hasBorders() const {
00170     return m_bordersList.size() != 0;
00171   }
00173   std::vector<MWAWBorder> const &borders() const {
00174     return m_bordersList;
00175   }
00176 
00178   void resetBorders() {
00179     m_bordersList.resize(0);
00180   }
00182   void setBorders(int wh, MWAWBorder const &border);
00183 
00185   MWAWColor backgroundColor() const {
00186     return m_backgroundColor;
00187   }
00189   void setBackgroundColor(MWAWColor color) {
00190     m_backgroundColor = color;
00191   }
00193   bool hasExtraLine() const {
00194     return m_extraLine!=E_None && !m_extraLineType.isEmpty();
00195   }
00197   ExtraLine extraLine() const {
00198     return m_extraLine;
00199   }
00201   MWAWBorder const &extraLineType() const {
00202     return m_extraLineType;
00203   }
00205   void setExtraLine(ExtraLine extrLine, MWAWBorder const &type=MWAWBorder()) {
00206     m_extraLine = extrLine;
00207     m_extraLineType=type;
00208   }
00209 protected:
00211   Vec2i m_position;
00213   Vec2i m_numberCellSpanned;
00214 
00216   Box2f m_bdBox;
00217 
00219   Vec2f m_bdSize;
00220 
00222   HorizontalAlignment m_hAlign;
00224   VerticalAlignment m_vAlign;
00226   std::vector<MWAWBorder> m_bordersList;
00228   MWAWColor m_backgroundColor;
00230   bool m_protected;
00232   ExtraLine m_extraLine;
00234   MWAWBorder m_extraLineType;
00235 };
00236 
00237 #endif
00238 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: