Main Page
Namespaces
Classes
Files
File List
File Members
MWAWCell.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
38
#ifndef MWAW_CELL_H
39
# define MWAW_CELL_H
40
41
#include <string>
42
#include <vector>
43
44
#include "
libmwaw_internal.hxx
"
45
46
#include "
MWAWEntry.hxx
"
47
#include "
MWAWFont.hxx
"
48
49
class
MWAWTable
;
50
52
class
MWAWCell
53
{
54
public
:
56
enum
FormatType
{
F_TEXT
,
F_BOOLEAN
,
F_NUMBER
,
F_DATE
,
F_TIME
,
F_UNKNOWN
};
58
enum
NumberType
{
F_NUMBER_CURRENCY
,
F_NUMBER_DECIMAL
,
F_NUMBER_FRACTION
,
F_NUMBER_GENERIC
,
F_NUMBER_SCIENTIFIC
,
F_NUMBER_PERCENT
,
F_NUMBER_UNKNOWN
};
60
struct
Format
{
62
Format
() :
m_format
(
F_UNKNOWN
),
m_numberFormat
(
F_NUMBER_UNKNOWN
),
m_digits
(-1),
m_integerDigits
(-1),
m_numeratorDigits
(-1),
m_denominatorDigits
(-1),
63
m_thousandHasSeparator
(false),
m_parenthesesForNegative
(false),
m_currencySymbol
(
"$"
),
m_DTFormat
(
""
)
64
{
65
}
67
virtual
~Format
() {}
69
bool
hasBasicFormat
()
const
70
{
71
return
m_format
==
F_TEXT
||
m_format
==
F_UNKNOWN
;
72
}
74
std::string
getValueType
()
const
;
76
bool
getNumberingProperties
(librevenge::RVNGPropertyList &propList)
const
;
78
static
bool
convertDTFormat
(std::string
const
&dtFormat, librevenge::RVNGPropertyListVector &propListVector);
80
friend
std::ostream &
operator<<
(std::ostream &o,
Format
const
&format);
82
int
compare
(
Format
const
&format)
const
;
83
85
FormatType
m_format
;
87
NumberType
m_numberFormat
;
89
int
m_digits
;
91
int
m_integerDigits
;
93
int
m_numeratorDigits
;
95
int
m_denominatorDigits
;
97
bool
m_thousandHasSeparator
;
99
bool
m_parenthesesForNegative
;
101
std::string
m_currencySymbol
;
103
std::string
m_DTFormat
;
104
};
106
struct
CompareFormat
{
108
CompareFormat
() {}
110
bool
operator()
(
Format
const
&c1,
Format
const
&c2)
const
111
{
112
return
c1.
compare
(c2) < 0;
113
}
114
};
118
enum
HorizontalAlignment
{
HALIGN_LEFT
,
HALIGN_RIGHT
,
HALIGN_CENTER
,
119
HALIGN_FULL
,
HALIGN_DEFAULT
120
};
121
124
enum
VerticalAlignment
{
VALIGN_TOP
,
VALIGN_CENTER
,
VALIGN_BOTTOM
,
VALIGN_DEFAULT
};
125
127
enum
ExtraLine
{
E_None
,
E_Line1
,
E_Line2
,
E_Cross
};
128
130
MWAWCell
() :
m_position
(0,0),
m_numberCellSpanned
(1,1),
m_bdBox
(),
m_bdSize
(),
131
m_format
(),
m_font
(3,12),
m_fontSet
(false),
m_hAlign
(
HALIGN_DEFAULT
),
m_vAlign
(
VALIGN_DEFAULT
),
132
m_backgroundColor
(
MWAWColor
::white()),
m_protected
(false),
133
m_bordersList
(),
m_extraLine
(
E_None
),
m_extraLineType
() { }
134
136
virtual
~MWAWCell
() {}
137
139
void
addTo
(librevenge::RVNGPropertyList &propList, shared_ptr<MWAWFontConverter> fontConverter)
const
;
140
142
friend
std::ostream &
operator<<
(std::ostream &o,
MWAWCell
const
&cell);
143
144
// interface with MWAWTable:
145
150
virtual
bool
send
(
MWAWListenerPtr
listener,
MWAWTable
&table);
155
virtual
bool
sendContent
(
MWAWListenerPtr
listener,
MWAWTable
&table);
156
157
// position
158
160
MWAWVec2i
const
&
position
()
const
161
{
162
return
m_position
;
163
}
165
void
setPosition
(
MWAWVec2i
posi)
166
{
167
m_position
= posi;
168
}
169
171
MWAWVec2i
const
&
numSpannedCells
()
const
172
{
173
return
m_numberCellSpanned
;
174
}
176
void
setNumSpannedCells
(
MWAWVec2i
numSpanned)
177
{
178
m_numberCellSpanned
=numSpanned;
179
}
180
182
MWAWBox2f
const
&
bdBox
()
const
183
{
184
return
m_bdBox
;
185
}
187
void
setBdBox
(
MWAWBox2f
box)
188
{
189
m_bdBox
= box;
190
}
191
193
MWAWVec2f
const
&
bdSize
()
const
194
{
195
return
m_bdSize
;
196
}
198
void
setBdSize
(
MWAWVec2f
sz)
199
{
200
m_bdSize
= sz;
201
}
203
static
std::string
getBasicCellName
(
MWAWVec2i
const
&pos);
205
static
std::string
getCellName
(
MWAWVec2i
const
&pos,
MWAWVec2b
const
&absolute);
206
208
static
std::string
getColumnName
(
int
col);
209
210
// format
211
213
Format
const
&
getFormat
()
const
214
{
215
return
m_format
;
216
}
218
void
setFormat
(
Format
const
&format)
219
{
220
m_format
=format;
221
}
222
224
bool
isFontSet
()
const
225
{
226
return
m_fontSet
;
227
}
229
MWAWFont
getFont
()
const
230
{
231
return
m_font
;
232
}
234
void
setFont
(
MWAWFont
const
&font,
bool
isDefault=
false
)
235
{
236
m_font
=font;
237
m_fontSet
=!isDefault;
238
}
239
241
bool
isProtected
()
const
242
{
243
return
m_protected
;
244
}
246
void
setProtected
(
bool
fl)
247
{
248
m_protected
= fl;
249
}
250
252
HorizontalAlignment
hAlignment
()
const
253
{
254
return
m_hAlign
;
255
}
257
void
setHAlignment
(
HorizontalAlignment
align)
258
{
259
m_hAlign
= align;
260
}
261
263
VerticalAlignment
vAlignment
()
const
264
{
265
return
m_vAlign
;
266
}
268
void
setVAlignment
(
VerticalAlignment
align)
269
{
270
m_vAlign
= align;
271
}
272
274
bool
hasBorders
()
const
275
{
276
return
m_bordersList
.size() != 0;
277
}
279
std::vector<MWAWBorder>
const
&
borders
()
const
280
{
281
return
m_bordersList
;
282
}
283
285
void
resetBorders
()
286
{
287
m_bordersList
.resize(0);
288
}
290
void
setBorders
(
int
wh,
MWAWBorder
const
&border);
291
293
MWAWColor
backgroundColor
()
const
294
{
295
return
m_backgroundColor
;
296
}
298
void
setBackgroundColor
(
MWAWColor
color)
299
{
300
m_backgroundColor
= color;
301
}
303
bool
hasExtraLine
()
const
304
{
305
return
m_extraLine
!=
E_None
&& !
m_extraLineType
.
isEmpty
();
306
}
308
ExtraLine
extraLine
()
const
309
{
310
return
m_extraLine
;
311
}
313
MWAWBorder
const
&
extraLineType
()
const
314
{
315
return
m_extraLineType
;
316
}
318
void
setExtraLine
(
ExtraLine
extrLine,
MWAWBorder
const
&type=
MWAWBorder
())
319
{
320
m_extraLine
= extrLine;
321
m_extraLineType
=type;
322
}
323
protected
:
325
MWAWVec2i
m_position
;
327
MWAWVec2i
m_numberCellSpanned
;
329
MWAWBox2f
m_bdBox
;
331
MWAWVec2f
m_bdSize
;
332
334
Format
m_format
;
336
MWAWFont
m_font
;
338
bool
m_fontSet
;
340
HorizontalAlignment
m_hAlign
;
342
VerticalAlignment
m_vAlign
;
344
MWAWColor
m_backgroundColor
;
346
bool
m_protected
;
347
349
std::vector<MWAWBorder>
m_bordersList
;
351
ExtraLine
m_extraLine
;
353
MWAWBorder
m_extraLineType
;
354
};
355
357
class
MWAWCellContent
358
{
359
public
:
361
struct
FormulaInstruction
{
362
enum
Type
{
F_Operator
,
F_Function
,
F_Cell
,
F_CellList
,
F_Long
,
F_Double
,
F_Text
};
364
FormulaInstruction
() :
m_type
(
F_Text
),
m_content
(
""
),
m_longValue
(0),
m_doubleValue
(0),
m_sheet
(
""
)
365
{
366
for
(
int
i=0; i<2; ++i) {
367
m_position
[i]=
MWAWVec2i
(0,0);
368
m_positionRelative
[i]=
MWAWVec2b
(
false
,
false
);
369
}
370
}
372
librevenge::RVNGPropertyList
getPropertyList
(
MWAWFontConverter
&fontConverter,
int
fontId)
const
;
374
friend
std::ostream &
operator<<
(std::ostream &o,
FormulaInstruction
const
&inst);
376
Type
m_type
;
378
std::string
m_content
;
380
double
m_longValue
;
382
double
m_doubleValue
;
384
MWAWVec2i
m_position
[2];
386
MWAWVec2b
m_positionRelative
[2];
388
std::string
m_sheet
;
389
};
390
392
enum
Type
{
C_NONE
,
C_TEXT
,
C_NUMBER
,
C_FORMULA
,
C_UNKNOWN
};
394
MWAWCellContent
() :
m_contentType
(
C_UNKNOWN
),
m_value
(0.0),
m_valueSet
(false),
m_textEntry
(),
m_formula
() { }
396
~MWAWCellContent
() {}
398
friend
std::ostream &
operator<<
(std::ostream &o,
MWAWCellContent
const
&cell);
399
401
bool
empty
()
const
402
{
403
if
(
m_contentType
==
C_NUMBER
)
return
false
;
404
if
(
m_contentType
==
C_TEXT
&&
m_textEntry
.
valid
())
return
false
;
405
if
(
m_contentType
==
C_FORMULA
&& (
m_formula
.size() ||
isValueSet
()))
return
false
;
406
return
true
;
407
}
409
void
setValue
(
double
value)
410
{
411
m_value
= value;
412
m_valueSet
=
true
;
413
}
415
bool
isValueSet
()
const
416
{
417
return
m_valueSet
;
418
}
420
bool
hasText
()
const
421
{
422
return
m_textEntry
.
valid
();
423
}
426
static
bool
double2Date
(
double
val,
int
&Y,
int
&M,
int
&D);
428
static
bool
double2Time
(
double
val,
int
&H,
int
&M,
int
&S);
430
static
bool
double2String
(
double
val,
MWAWCell::Format
const
&format, std::string &str);
432
static
bool
date2Double
(
int
Y,
int
M,
int
D,
double
&val);
434
Type
m_contentType
;
436
double
m_value
;
438
bool
m_valueSet
;
440
MWAWEntry
m_textEntry
;
442
std::vector<FormulaInstruction>
m_formula
;
443
};
444
445
#endif
446
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Generated on Tue Mar 1 2016 23:42:50 for libmwaw by
doxygen
1.8.4