WPSCell.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwps
00003  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
00004  * Copyright (C) 2006, 2007 Andrew Ziem
00005  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00006  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
00007  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00022  *
00023  * For further information visit http://libwps.sourceforge.net
00024  */
00025 
00026 /* "This product is not manufactured, approved, or supported by
00027  * Corel Corporation or Corel Corporation Limited."
00028  */
00029 
00030 /* Define some classes used to store a Cell
00031  */
00032 
00033 #ifndef WPS_CELL_H
00034 #  define WPS_CELL_H
00035 
00036 #include <iostream>
00037 
00038 #include "libwps_internal.h"
00039 
00040 class WPXPropertyList;
00041 class WPSContentListener;
00042 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
00043 
00045 class WPSCellFormat
00046 {
00047 public:
00051         enum HorizontalAlignment { HALIGN_LEFT, HALIGN_RIGHT, HALIGN_CENTER,
00052                                    HALIGN_FULL, HALIGN_DEFAULT
00053                                  };
00055         WPSCellFormat() :
00056                 m_hAlign(HALIGN_DEFAULT), m_bordersList(0) { }
00057 
00058         virtual ~WPSCellFormat() {}
00059 
00060 
00062         HorizontalAlignment hAlignement() const
00063         {
00064                 return m_hAlign;
00065         }
00067         void setHAlignement(HorizontalAlignment align)
00068         {
00069                 m_hAlign = align;
00070         }
00071 
00073         bool hasBorders() const
00074         {
00075                 return m_bordersList != 0;
00076         }
00078         int borders() const
00079         {
00080                 return m_bordersList;
00081         }
00083         void setBorders(int bList)
00084         {
00085                 m_bordersList = bList;
00086         }
00087 
00089         int compare(WPSCellFormat const &cell) const;
00090 
00092         friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
00093 
00094 protected:
00096         HorizontalAlignment m_hAlign;
00098         int m_bordersList;
00099 };
00100 
00101 class WPSTable;
00102 
00104 class WPSCell : public WPSCellFormat
00105 {
00106         friend class WPSTable;
00107 public:
00109         WPSCell() : WPSCellFormat(), m_box(), m_position(0,0), m_numberCellSpanned(1,1) {}
00110 
00112         void setBox(Box2f const &b)
00113         {
00114                 m_box = b;
00115         }
00117         Box2f const &box() const
00118         {
00119                 return m_box;
00120         }
00122         Vec2i &position()
00123         {
00124                 return m_position;
00125         }
00127         Vec2i const &position() const
00128         {
00129                 return m_position;
00130         }
00132         void setPosition(Vec2i posi)
00133         {
00134                 m_position = posi;
00135         }
00136 
00138         Vec2i const &numSpannedCells() const
00139         {
00140                 return m_numberCellSpanned;
00141         }
00143         void setNumSpannedCells(Vec2i numSpanned)
00144         {
00145                 m_numberCellSpanned=numSpanned;
00146         }
00147 
00149         virtual bool send(WPSContentListenerPtr &listener) = 0;
00150 
00152         virtual bool sendContent(WPSContentListenerPtr &listener) = 0;
00153 
00155         friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
00156 
00157 protected:
00159         struct Compare
00160         {
00161                 Compare(int dim) : m_coord(dim) {}
00163                 struct Point
00164                 {
00165                         Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
00166                         float getPos(int coord) const
00167                         {
00168                                 if (m_which)
00169                                         return m_cell->box().max()[coord];
00170                                 return m_cell->box().min()[coord];
00171                         }
00172                         float getSize(int coord) const
00173                         {
00174                                 return m_cell->box().size()[coord];
00175                         }
00176                         int m_which;
00177                         WPSCell const *m_cell;
00178                 };
00179 
00181                 bool operator()(Point const &c1, Point const &c2) const
00182                 {
00183                         float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
00184                         if (diffF) return (diffF < 0);
00185                         int diff = c2.m_which - c1.m_which;
00186                         if (diff) return (diff < 0);
00187                         diffF = c1.m_cell->box().size()[m_coord]
00188                                 - c2.m_cell->box().size()[m_coord];
00189                         if (diffF) return (diffF < 0);
00190                         return long(c1.m_cell) < long(c2.m_cell);
00191                 }
00192 
00194                 int m_coord;
00195         };
00196 
00198         Box2f m_box;
00200         Vec2i m_position;
00202         Vec2i m_numberCellSpanned;
00203 };
00204 
00205 typedef shared_ptr<WPSCell> WPSCellPtr;
00206 
00207 #endif
00208 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */