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
* Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
4
* Copyright (C) 2006, 2007 Andrew Ziem
5
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
6
* Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
7
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
8
*
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Library General Public
11
* License as published by the Free Software Foundation; either
12
* version 2 of the License, or (at your option) any later version.
13
*
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Library General Public License for more details.
18
*
19
* You should have received a copy of the GNU Library General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*
23
* For further information visit http://libwps.sourceforge.net
24
*/
25
26
/* "This product is not manufactured, approved, or supported by
27
* Corel Corporation or Corel Corporation Limited."
28
*/
29
30
/* Define some classes used to store a Cell
31
*/
32
33
#ifndef WPS_CELL_H
34
# define WPS_CELL_H
35
36
#include <iostream>
37
38
#include "
libwps_internal.h
"
39
40
class
WPXPropertyList;
41
class
WPSContentListener
;
42
typedef
shared_ptr<WPSContentListener>
WPSContentListenerPtr
;
43
45
class
WPSCellFormat
46
{
47
public
:
51
enum
HorizontalAlignment
{
HALIGN_LEFT
,
HALIGN_RIGHT
,
HALIGN_CENTER
,
52
HALIGN_FULL
,
HALIGN_DEFAULT
53
};
55
WPSCellFormat
() :
56
m_hAlign
(
HALIGN_DEFAULT
),
m_bordersList
(0) { }
57
58
virtual
~WPSCellFormat
() {}
59
60
62
HorizontalAlignment
hAlignement
()
const
63
{
64
return
m_hAlign
;
65
}
67
void
setHAlignement
(
HorizontalAlignment
align)
68
{
69
m_hAlign
= align;
70
}
71
73
bool
hasBorders
()
const
74
{
75
return
m_bordersList
!= 0;
76
}
78
int
borders
()
const
79
{
80
return
m_bordersList
;
81
}
83
void
setBorders
(
int
bList)
84
{
85
m_bordersList
= bList;
86
}
87
89
int
compare
(
WPSCellFormat
const
&cell)
const
;
90
92
friend
std::ostream &
operator<<
(std::ostream &o,
WPSCellFormat
const
&cell);
93
94
protected
:
96
HorizontalAlignment
m_hAlign
;
98
int
m_bordersList
;
99
};
100
101
class
WPSTable
;
102
104
class
WPSCell
:
public
WPSCellFormat
105
{
106
friend
class
WPSTable
;
107
public
:
109
WPSCell
() :
WPSCellFormat
(),
m_box
(),
m_position
(0,0),
m_numberCellSpanned
(1,1) {}
110
112
void
setBox
(
Box2f
const
&b)
113
{
114
m_box
= b;
115
}
117
Box2f
const
&
box
()
const
118
{
119
return
m_box
;
120
}
122
Vec2i
&
position
()
123
{
124
return
m_position
;
125
}
127
Vec2i
const
&
position
()
const
128
{
129
return
m_position
;
130
}
132
void
setPosition
(
Vec2i
posi)
133
{
134
m_position
= posi;
135
}
136
138
Vec2i
const
&
numSpannedCells
()
const
139
{
140
return
m_numberCellSpanned
;
141
}
143
void
setNumSpannedCells
(
Vec2i
numSpanned)
144
{
145
m_numberCellSpanned
=numSpanned;
146
}
147
149
virtual
bool
send
(
WPSContentListenerPtr
&listener) = 0;
150
152
virtual
bool
sendContent
(
WPSContentListenerPtr
&listener) = 0;
153
155
friend
std::ostream &
operator<<
(std::ostream &o,
WPSCell
const
&cell);
156
157
protected
:
159
struct
Compare
160
{
161
Compare
(
int
dim) :
m_coord
(dim) {}
163
struct
Point
164
{
165
Point
(
int
wh,
WPSCell
const
*cell) :
m_which
(wh),
m_cell
(cell) {}
166
float
getPos
(
int
coord)
const
167
{
168
if
(
m_which
)
169
return
m_cell
->
box
().
max
()[coord];
170
return
m_cell
->
box
().
min
()[coord];
171
}
172
float
getSize
(
int
coord)
const
173
{
174
return
m_cell
->
box
().
size
()[coord];
175
}
176
int
m_which
;
177
WPSCell
const
*
m_cell
;
178
};
179
181
bool
operator()
(
Point
const
&c1,
Point
const
&c2)
const
182
{
183
float
diffF = c1.
getPos
(
m_coord
)-c2.
getPos
(
m_coord
);
184
if
(diffF)
return
(diffF < 0);
185
int
diff = c2.
m_which
- c1.
m_which
;
186
if
(diff)
return
(diff < 0);
187
diffF = c1.
m_cell
->
box
().
size
()[
m_coord
]
188
- c2.
m_cell
->
box
().
size
()[
m_coord
];
189
if
(diffF)
return
(diffF < 0);
190
return
long(c1.
m_cell
) < long(c2.
m_cell
);
191
}
192
194
int
m_coord
;
195
};
196
198
Box2f
m_box
;
200
Vec2i
m_position
;
202
Vec2i
m_numberCellSpanned
;
203
};
204
205
typedef
shared_ptr<WPSCell>
WPSCellPtr
;
206
207
#endif
208
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Generated on Wed Aug 8 2012 16:07:56 for libwps by
doxygen
1.8.1.2