Main Page
Namespaces
Classes
Files
File List
File Members
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_HELPER
41
# define MWAW_TABLE_HELPER
42
43
#include <iostream>
44
#include <vector>
45
46
#include "
libmwaw_internal.hxx
"
47
48
class
MWAWContentListener
;
49
typedef
shared_ptr<MWAWContentListener>
MWAWContentListenerPtr
;
50
51
52
class
MWAWTable
;
53
55
class
MWAWTableCell
56
{
57
friend
class
MWAWTable
;
58
public
:
60
MWAWTableCell
() :
m_box
(),
m_position
(-1,-1),
m_numberCellSpanned
() {
61
}
63
virtual
~MWAWTableCell
() { }
65
void
setBox
(
Box2f
const
&dim) {
66
m_box
= dim;
67
}
69
Box2f
const
&
box
()
const
{
70
return
m_box
;
71
}
72
74
friend
std::ostream &
operator<<
(std::ostream &o,
MWAWTableCell
const
&cell) {
75
if
(cell.
m_position
.
x
() >= 0) {
76
o <<
"pos="
<< cell.
m_position
<<
","
;
77
if
(cell.
m_numberCellSpanned
[0]!=1 || cell.
m_numberCellSpanned
[1]!=1)
78
o <<
"span="
<< cell.
m_position
<<
","
;
79
}
80
o <<
"box="
<< cell.
m_box
<<
","
;
81
return
o;
82
}
83
85
virtual
bool
send
(
MWAWContentListenerPtr
listener) = 0;
86
88
virtual
bool
sendContent
(
MWAWContentListenerPtr
listener) = 0;
89
90
protected
:
92
struct
Compare
{
93
Compare
(
int
dim) :
m_coord
(dim) {}
95
struct
Point
{
96
Point
(
int
wh,
MWAWTableCell
const
*cell) :
m_which
(wh),
m_cell
(cell) {}
97
float
getPos
(
int
coord)
const
{
98
if
(
m_which
)
99
return
m_cell
->
box
().
max
()[coord];
100
return
m_cell
->
box
().
min
()[coord];
101
}
102
float
getSize
(
int
coord)
const
{
103
return
m_cell
->
box
().
size
()[coord];
104
}
105
int
m_which
;
106
MWAWTableCell
const
*
m_cell
;
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
long(c1.
m_cell
) < long(c2.
m_cell
);
121
}
122
124
int
m_coord
;
125
};
126
127
protected
:
129
Box2f
m_box
;
130
132
Vec2i
m_position
,
m_numberCellSpanned
;
133
};
134
135
class
MWAWTable
136
{
137
public
:
139
MWAWTable
() :
m_cellsList
(),
m_rowsSize
(),
m_colsSize
() {}
140
142
virtual
~MWAWTable
();
143
145
void
add
(shared_ptr<MWAWTableCell> cell) {
146
m_cellsList
.push_back(cell);
147
}
148
150
int
numCells
()
const
{
151
return
int(
m_cellsList
.size());
152
}
154
shared_ptr<MWAWTableCell>
get
(
int
id);
155
160
bool
sendTable
(
MWAWContentListenerPtr
listener);
161
165
virtual
void
sendPreTableData
(
MWAWContentListenerPtr
) {}
166
168
bool
sendAsText
(
MWAWContentListenerPtr
listener);
169
170
protected
:
172
bool
buildStructures
();
173
175
std::vector<shared_ptr<MWAWTableCell> >
m_cellsList
;
177
std::vector<float>
m_rowsSize
,
m_colsSize
;
178
};
179
180
#endif
Generated on Tue Apr 30 2013 06:31:14 for libmwaw by
doxygen
1.8.3.1