WPSCell.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3  * Version: MPL 2.0 / LGPLv2.1+
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Major Contributor(s):
10  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11  * Copyright (C) 2006, 2007 Andrew Ziem
12  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15  *
16  * For minor contributions see the git repository.
17  *
18  * Alternatively, the contents of this file may be used under the terms
19  * of the GNU Lesser General Public License Version 2.1 or later
20  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21  * applicable instead of those above.
22  *
23  * For further information visit http://libwps.sourceforge.net
24  */
25 
26 /* Define some classes used to store a Cell
27  */
28 
29 #ifndef WPS_CELL_H
30 # define WPS_CELL_H
31 
32 #include <iostream>
33 #include <vector>
34 
35 #include "libwps_internal.h"
36 
37 class WPXPropertyList;
39 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
40 
43 {
44 public:
50  };
54 
55  virtual ~WPSCellFormat() {}
56 
57 
60  {
61  return m_hAlign;
62  }
65  {
66  m_hAlign = align;
67  }
68 
70  bool hasBorders() const
71  {
72  return m_bordersList.size() != 0;
73  }
74 
76  std::vector<WPSBorder> const &borders() const
77  {
78  return m_bordersList;
79  }
80 
82  void resetBorders()
83  {
84  m_bordersList.resize(0);
85  }
86 
88  void setBorders(int wh, WPSBorder const &border);
89 
91  uint32_t backgroundColor() const
92  {
93  return m_backgroundColor;
94  }
96  void setBackgroundColor(uint32_t color)
97  {
98  m_backgroundColor = color;
99  }
100 
102  int compare(WPSCellFormat const &cell) const;
103 
105  friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell);
106 
107 protected:
111  std::vector<WPSBorder> m_bordersList;
114 };
115 
116 class WPSTable;
117 
119 class WPSCell : public WPSCellFormat
120 {
121  friend class WPSTable;
122 public:
125 
127  void setBox(Box2f const &b)
128  {
129  m_box = b;
130  }
132  Box2f const &box() const
133  {
134  return m_box;
135  }
137  bool isVerticalSet() const
138  {
139  return m_verticalSet;
140  }
142  void setVerticalSet(bool verticalSet)
143  {
144  m_verticalSet = verticalSet;
145  }
148  {
149  return m_position;
150  }
152  Vec2i const &position() const
153  {
154  return m_position;
155  }
157  void setPosition(Vec2i posi)
158  {
159  m_position = posi;
160  }
161 
163  Vec2i const &numSpannedCells() const
164  {
165  return m_numberCellSpanned;
166  }
168  void setNumSpannedCells(Vec2i numSpanned)
169  {
170  m_numberCellSpanned=numSpanned;
171  }
172 
174  virtual bool send(WPSContentListenerPtr &listener) = 0;
175 
177  virtual bool sendContent(WPSContentListenerPtr &listener) = 0;
178 
180  friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell);
181 
182 protected:
184  struct Compare
185  {
186  Compare(int dim) : m_coord(dim) {}
188  struct Point
189  {
190  Point(int wh, WPSCell const *cell) : m_which(wh), m_cell(cell) {}
191  float getPos(int coord) const
192  {
193  if (m_which)
194  return m_cell->box().max()[coord];
195  return m_cell->box().min()[coord];
196  }
197  float getSize(int coord) const
198  {
199  return m_cell->box().size()[coord];
200  }
201  int m_which;
202  WPSCell const *m_cell;
203  };
204 
206  bool operator()(Point const &c1, Point const &c2) const
207  {
208  float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
209  if (diffF < 0) return true;
210  if (diffF > 0) return false;
211  int diff = c2.m_which - c1.m_which;
212  if (diff) return (diff < 0);
213  diffF = c1.m_cell->box().size()[m_coord]
214  - c2.m_cell->box().size()[m_coord];
215  if (diffF < 0) return true;
216  if (diffF > 0) return false;
217  if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet;
218  return long(c1.m_cell) < long(c2.m_cell);
219  }
220 
222  int m_coord;
223  };
224 
233 };
234 
235 typedef shared_ptr<WPSCell> WPSCellPtr;
236 
237 #endif
238 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
void setBox(Box2f const &b)
set the bounding box (units in point)
Definition: WPSCell.h:127
friend std::ostream & operator<<(std::ostream &o, WPSCellFormat const &cell)
operator&lt;&lt;
Definition: WPSCell.cpp:70
shared_ptr< WPSContentListener > WPSContentListenerPtr
Definition: WPSCell.h:38
a border list
Definition: libwps_internal.h:225
a comparaison structure used retrieve the rows and the columns
Definition: WPSCell.h:184
Point(int wh, WPSCell const *cell)
Definition: WPSCell.h:190
int compare(WPSCellFormat const &cell) const
a comparison function
Definition: WPSCell.cpp:54
Vec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:517
Vec2i m_numberCellSpanned
the cell spanned : by default (1,1)
Definition: WPSCell.h:232
bool hasBorders() const
return true if the cell has some border
Definition: WPSCell.h:70
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=WPSBorder::LeftBit|...
Definition: WPSCell.cpp:34
virtual bool send(WPSContentListenerPtr &listener)=0
call when a cell must be send
WPSCell()
constructor
Definition: WPSCell.h:124
void setVerticalSet(bool verticalSet)
fixes or not the vertical size
Definition: WPSCell.h:142
float getSize(int coord) const
Definition: WPSCell.h:197
HorizontalAlignment m_hAlign
the cell alignement : by default nothing
Definition: WPSCell.h:109
Definition: WPSCell.h:48
a structure used to defined the cell format
Definition: WPSCell.h:42
Definition: WPSContentListener.h:168
uint32_t backgroundColor() const
returns the background color
Definition: WPSCell.h:91
uint32_t m_backgroundColor
the backgroung color
Definition: WPSCell.h:113
Vec2i const & numSpannedCells() const
returns the number of spanned cells
Definition: WPSCell.h:163
a structure used to defined the cell position, and a format
Definition: WPSCell.h:119
void setNumSpannedCells(Vec2i numSpanned)
sets the number of spanned cells : Vec2i(1,1) means 1 cellule
Definition: WPSCell.h:168
bool isVerticalSet() const
returns true if the vertical is fixed
Definition: WPSCell.h:137
HorizontalAlignment hAlignement() const
returns the horizontal alignement
Definition: WPSCell.h:59
std::vector< WPSBorder > m_bordersList
the cell border WPSBorder::Pos
Definition: WPSCell.h:111
Box2f m_box
the cell bounding box (unit in point)
Definition: WPSCell.h:226
int m_coord
the coord to compare
Definition: WPSCell.h:222
Vec2i const & position() const
position accessor
Definition: WPSCell.h:152
Vec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:522
Compare(int dim)
Definition: WPSCell.h:186
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: WPSCell.h:206
small structure to define a cell point
Definition: WPSCell.h:188
float getPos(int coord) const
Definition: WPSCell.h:191
void setBackgroundColor(uint32_t color)
set the background color
Definition: WPSCell.h:96
void resetBorders()
reset the border
Definition: WPSCell.h:82
Definition: WPSCell.h:49
Box2f const & box() const
return the bounding box
Definition: WPSCell.h:132
void setPosition(Vec2i posi)
set the cell positions : 0,0 -&gt; A1, 0,1 -&gt; A2
Definition: WPSCell.h:157
Vec2i m_position
the cell row and column : 0,0 -&gt; A1, 0,1 -&gt; A2
Definition: WPSCell.h:230
WPSCell const * m_cell
Definition: WPSCell.h:202
void setHAlignement(HorizontalAlignment align)
sets the horizontal alignement
Definition: WPSCell.h:64
Definition: WPSCell.h:48
Definition: WPSCell.h:49
int m_which
Definition: WPSCell.h:201
std::vector< WPSBorder > const & borders() const
return the cell border: libwps::LeftBit | ...
Definition: WPSCell.h:76
virtual ~WPSCellFormat()
Definition: WPSCell.h:55
Definition: WPSTable.h:45
bool m_verticalSet
true if y size is fixed
Definition: WPSCell.h:228
virtual bool sendContent(WPSContentListenerPtr &listener)=0
call when the content of a cell must be send
Vec2< T > size() const
the box size
Definition: libwps_internal.h:547
friend std::ostream & operator<<(std::ostream &o, WPSCell const &cell)
operator&lt;&lt;
Definition: WPSCell.cpp:111
shared_ptr< WPSCell > WPSCellPtr
Definition: WPSCell.h:235
Definition: WPSCell.h:48
HorizontalAlignment
the default horizontal alignement.
Definition: WPSCell.h:48
Vec2i & position()
position accessor
Definition: WPSCell.h:147
WPSCellFormat()
constructor
Definition: WPSCell.h:52

Generated on Wed Jun 11 2014 02:26:01 for libwps by doxygen 1.8.5