Main Page
Namespaces
Classes
Files
File List
File Members
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;
38
class
WPSContentListener
;
39
typedef
shared_ptr<WPSContentListener>
WPSContentListenerPtr
;
40
42
class
WPSCellFormat
43
{
44
public
:
48
enum
HorizontalAlignment
{
HALIGN_LEFT
,
HALIGN_RIGHT
,
HALIGN_CENTER
,
49
HALIGN_FULL
,
HALIGN_DEFAULT
50
};
52
WPSCellFormat
() :
53
m_hAlign
(
HALIGN_DEFAULT
),
m_bordersList
(),
m_backgroundColor
(0xFFFFFF) { }
54
55
virtual
~WPSCellFormat
() {}
56
57
59
HorizontalAlignment
hAlignement
()
const
60
{
61
return
m_hAlign
;
62
}
64
void
setHAlignement
(
HorizontalAlignment
align)
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
:
109
HorizontalAlignment
m_hAlign
;
111
std::vector<WPSBorder>
m_bordersList
;
113
uint32_t
m_backgroundColor
;
114
};
115
116
class
WPSTable
;
117
119
class
WPSCell
:
public
WPSCellFormat
120
{
121
friend
class
WPSTable
;
122
public
:
124
WPSCell
() :
WPSCellFormat
(),
m_box
(),
m_verticalSet
(true),
m_position
(0,0),
m_numberCellSpanned
(1,1) {}
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
}
147
Vec2i
&
position
()
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
226
Box2f
m_box
;
228
bool
m_verticalSet
;
230
Vec2i
m_position
;
232
Vec2i
m_numberCellSpanned
;
233
};
234
235
typedef
shared_ptr<WPSCell>
WPSCellPtr
;
236
237
#endif
238
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Generated on Thu Aug 29 2013 23:39:57 for libwps by
doxygen
1.8.4