[go: up one dir, main page]

Menu

[2117e7]: / src / lib / WPSTable.h  Maximize  Restore  History

Download this file

200 lines (183 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* libwps
* Version: MPL 2.0 / LGPLv2.1+
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Major Contributor(s):
* Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU Lesser General Public License Version 2.1 or later
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
* applicable instead of those above.
*
* For further information visit http://libwps.sourceforge.net
*/
#ifndef WPS_TABLE
# define WPS_TABLE
#include <iostream>
#include <vector>
#include "libwps_internal.h"
/*
* Structure to store the column properties
*
* \note use only to define sheet properties, to be changed
*/
struct WPSColumnFormat
{
public:
//! constructor
explicit WPSColumnFormat(float width=-1)
: m_width(width)
, m_isPercentWidth(false)
, m_useOptimalWidth(false)
, m_isHeader(false)
, m_numRepeat(1)
{
}
//! add to the propList
void addTo(librevenge::RVNGPropertyList &propList) const;
/** a comparison function
\note this comparison function does ignore m_numRepeat
*/
int compare(WPSColumnFormat const &col) const
{
if (m_width<col.m_width) return 1;
if (m_width>col.m_width) return -1;
if (m_isPercentWidth!=col.m_isPercentWidth) return m_isPercentWidth ? 1 : -1;
if (m_useOptimalWidth!=col.m_useOptimalWidth) return m_useOptimalWidth ? 1 : -1;
if (m_isHeader!=col.m_isHeader) return m_isHeader ? 1 : -1;
return 0;
}
//! operator==
bool operator==(WPSColumnFormat const &col) const
{
return compare(col)==0;
}
//! operator!=
bool operator!=(WPSColumnFormat const &col) const
{
return compare(col)!=0;
}
//! operator<
bool operator<(WPSColumnFormat const &col) const
{
return compare(col)<0;
}
//! operator<<
friend std::ostream &operator<<(std::ostream &o, WPSColumnFormat const &col);
//! the column width, if known
float m_width;
//! a flag to know if the width is in percent (or in point)
bool m_isPercentWidth;
//! a flag to know if we need to see use-optimal column width
bool m_useOptimalWidth;
//! a flag to know if the column is a header column
bool m_isHeader;
//! the number times a column is repeated
int m_numRepeat;
};
/*
* Structure to store the row properties
*
* \note use only to define sheet properties, to be changed
*/
struct WPSRowFormat
{
public:
//! constructor
explicit WPSRowFormat(float height=-1)
: m_height(height)
, m_isMinimalHeight(false)
, m_useOptimalHeight(false)
, m_isHeader(false)
{
}
//! add to the propList
void addTo(librevenge::RVNGPropertyList &propList) const;
//! a comparison function
int compare(WPSRowFormat const &row) const
{
if (m_height<row.m_height) return 1;
if (m_height>row.m_height) return -1;
if (m_isMinimalHeight!=row.m_isMinimalHeight) return m_isMinimalHeight ? 1 : -1;
if (m_useOptimalHeight!=row.m_useOptimalHeight) return m_useOptimalHeight ? 1 : -1;
if (m_isHeader!=row.m_isHeader) return m_isHeader ? 1 : -1;
return 0;
}
//! operator==
bool operator==(WPSRowFormat const &row) const
{
return compare(row)==0;
}
//! operator!=
bool operator!=(WPSRowFormat const &row) const
{
return compare(row)!=0;
}
//! operator<
bool operator<(WPSRowFormat const &row) const
{
return compare(row)<0;
}
//! operator<<
friend std::ostream &operator<<(std::ostream &o, WPSRowFormat const &row);
//! the row height, if known
float m_height;
//! a flag to know if the height is only a minimum
bool m_isMinimalHeight;
//! a flag to know if we need to see use-optimal row height
bool m_useOptimalHeight;
//! a flag to know if the row is a header row
bool m_isHeader;
};
/*
* Structure to store and construct a table from an unstructured list
* of cell
*
*/
class WPSTable
{
public:
//! the constructor
WPSTable()
: m_cellsList()
, m_rowsSize()
, m_colsSize() {}
WPSTable &operator=(WPSTable const &)=default;
//! the destructor
virtual ~WPSTable();
//! add a new cells
void add(WPSCellPtr &cell);
//! returns the number of cell
int numCells() const
{
return int(m_cellsList.size());
}
//! returns the i^th cell
WPSCellPtr getCell(int id);
/** try to send the table
Note: either send the table ( and returns true ) or do nothing.
*/
bool sendTable(WPSContentListenerPtr listener);
/** try to send the table as basic text */
bool sendAsText(WPSContentListenerPtr listener);
protected:
//! create the correspondance list, ...
bool buildStructures();
/** the list of cells */
std::vector<WPSCellPtr> m_cellsList;
/** the final row and col size (in point) */
std::vector<float> m_rowsSize, m_colsSize;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */