MWAWTable.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33 
34 /*
35  * Structure to store and construct a table from an unstructured list
36  * of cell
37  *
38  */
39 
40 #ifndef MWAW_TABLE
41 # define MWAW_TABLE
42 
43 #include <iostream>
44 #include <vector>
45 
46 #include "libmwaw_internal.hxx"
47 
48 class MWAWTable;
49 
52 {
53  friend class MWAWTable;
54 public:
57  }
59  virtual ~MWAWTableCell() { }
61  void setBox(Box2f const &dim) {
62  m_box = dim;
63  }
65  Box2f const &box() const {
66  return m_box;
67  }
69  friend std::ostream &operator<<(std::ostream &o, MWAWTableCell const &cell) {
70  if (cell.m_position.x() >= 0) {
71  o << "pos=" << cell.m_position << ",";
72  if (cell.m_numberCellSpanned[0]!=1 || cell.m_numberCellSpanned[1]!=1)
73  o << "span=" << cell.m_position << ",";
74  }
75  o << "box=" << cell.m_box << ",";
76  return o;
77  }
78 
80  virtual bool send(MWAWContentListenerPtr listener) = 0;
81 
83  virtual bool sendContent(MWAWContentListenerPtr listener) = 0;
84 
85 protected:
87  struct Compare {
88  Compare(int dim) : m_coord(dim) {}
90  struct Point {
91  Point(int wh, MWAWTableCell const *cell, int cellId) : m_which(wh), m_cell(cell), m_cellId(cellId) {}
92  float getPos(int coord) const {
93  if (m_which)
94  return m_cell->box().max()[coord];
95  return m_cell->box().min()[coord];
96  }
98  float getSize(int coord) const {
99  return m_cell->box().size()[coord];
100  }
102  int m_which;
106  int m_cellId;
107  };
108 
110  bool operator()(Point const &c1, Point const &c2) const {
111  float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
112  if (diffF < 0) return true;
113  if (diffF > 0) return false;
114  int diff = c2.m_which - c1.m_which;
115  if (diff) return (diff < 0);
116  diffF = c1.m_cell->box().size()[m_coord]
117  - c2.m_cell->box().size()[m_coord];
118  if (diffF < 0) return true;
119  if (diffF > 0) return false;
120  return c1.m_cellId < c2.m_cellId;
121  }
122 
124  int m_coord;
125  };
126 
127 protected:
130 
133 };
134 
136 {
137 public:
140 
142  virtual ~MWAWTable();
143 
145  void add(shared_ptr<MWAWTableCell> cell) {
146  if (!cell) {
147  MWAW_DEBUG_MSG(("MWAWTable::add: must be called with a cell\n"));
148  return;
149  }
150  m_cellsList.push_back(cell);
151  }
152 
154  int numCells() const {
155  return int(m_cellsList.size());
156  }
158  shared_ptr<MWAWTableCell> get(int id);
159 
164  bool sendTable(MWAWContentListenerPtr listener);
165 
170 
172  bool sendAsText(MWAWContentListenerPtr listener);
173 
174 protected:
176  bool buildStructures();
177 
179  std::vector<shared_ptr<MWAWTableCell> > m_cellsList;
181  std::vector<float> m_rowsSize, m_colsSize;
182 };
183 
184 #endif

Generated on Wed Jul 10 2013 18:15:30 for libmwaw by doxygen 1.8.4