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
200
201
202
203
204
205
206
207
208
209
210
211
|
/*
* Copyright (c) 2005 Cyrille Berger <[email protected]>
* Copyright (c) 2006 Isaac Clerencia <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "krs_cell.h"
#include "manipulator.h"
#include "manipulator_data.h"
namespace Kross { namespace KSpreadCore {
Cell::Cell(KSpread::Cell* cell, KSpread::Sheet* sheet, uint col, uint row)
: Kross::Api::Class<Cell>("KSpreadCell"), m_cell(cell), m_sheet(sheet), m_col(col), m_row(row)
{
this->addFunction0< Kross::Api::Variant >("value", this, &Cell::value);
this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("setValue", this, &Cell::setValue);
this->addFunction0< Kross::Api::Variant >("column", this, &Cell::column);
this->addFunction0< Kross::Api::Variant >("row", this, &Cell::row);
this->addFunction0< Cell >("previousCell", this, &Cell::previousCell);
this->addFunction0< Cell >("nextCell", this, &Cell::nextCell);
this->addFunction1< void, Cell >("setPreviousCell", this, &Cell::setPreviousCell);
this->addFunction1< void, Cell >("setNextCell", this, &Cell::setNextCell);
this->addFunction0< Kross::Api::Variant >("name", this, &Cell::name);
this->addFunction0< Kross::Api::Variant >("fullName", this, &Cell::fullName);
this->addFunction0< Kross::Api::Variant >("comment", this, &Cell::comment);
this->addFunction1< void, Kross::Api::Variant >("setComment", this, &Cell::setComment);
this->addFunction0< Kross::Api::Variant >("getFormatString", this, &Cell::getFormatString);
this->addFunction1< void, Kross::Api::Variant >("setFormatString", this, &Cell::setFormatString);
this->addFunction0< Kross::Api::Variant >("text", this, &Cell::text);
this->addFunction1< void, Kross::Api::Variant >("setText", this, &Cell::setText);
this->addFunction0< Kross::Api::Variant >("textColor", this, &Cell::textColor);
this->addFunction1< void, Kross::Api::Variant >("setTextColor", this, &Cell::setTextColor);
this->addFunction0< Kross::Api::Variant >("backgroundColor", this, &Cell::backgroundColor);
this->addFunction1< void, Kross::Api::Variant >("setBackgroundColor", this, &Cell::setBackgroundColor);
}
Cell::~Cell() {
}
const TQString Cell::getClassName() const {
return "Kross::KSpreadCore::KSpreadCell";
}
TQVariant Cell::toVariant(const KSpread::Value& value) const
{
//Should we use following value-format enums here?
//fmt_None, fmt_Boolean, fmt_Number, fmt_Percent, fmt_Money, fmt_DateTime, fmt_Date, fmt_Time, fmt_String
switch(value.type()) {
case KSpread::Value::Empty:
return TQVariant();
case KSpread::Value::Boolean:
return TQVariant( value.asBoolean() );
case KSpread::Value::Integer:
return static_cast<TQ_LLONG>(value.asInteger());
case KSpread::Value::Float:
return (float)value.asFloat();
case KSpread::Value::String:
return value.asString();
case KSpread::Value::Array: {
TQValueList<TQVariant> colarray;
for(uint j = 0; j < value.rows(); j++) {
TQValueList<TQVariant> rowarray;
for( uint i = 0; i < value.columns(); i++) {
KSpread::Value v = value.element(i,j);
rowarray.append( toVariant(v) );
}
colarray.append(rowarray);
}
return colarray;
} break;
case KSpread::Value::CellRange:
//FIXME: not yet used
return TQVariant();
case KSpread::Value::Error:
return TQVariant();
}
return TQVariant();
}
TQVariant Cell::value() const {
return toVariant( m_cell->value() );
}
bool Cell::setValue(const TQVariant& value) {
KSpread::Value v = m_cell->value();
switch(value.type()) {
case TQVariant::Bool: v.setValue( value.toBool() ); break;
case TQVariant::ULongLong: v.setValue( (long)value.toLongLong() ); break;
case TQVariant::Int: v.setValue( value.toInt() ); break;
case TQVariant::Double: v.setValue( value.toDouble() ); break;
case TQVariant::String: v.setValue( value.toString() ); break;
case TQVariant::Date: v.setValue( value.toDate() ); break;
case TQVariant::Time: v.setValue( value.toTime() ); break;
case TQVariant::DateTime: v.setValue( value.toDateTime() ); break;
default: return false;
}
return true;
}
int Cell::column() const {
return m_cell->column();
}
int Cell::row() const {
return m_cell->row();
}
Cell* Cell::previousCell() const {
KSpread::Cell* c = m_cell->previousCell();
return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
}
Cell* Cell::nextCell() const {
KSpread::Cell* c = m_cell->nextCell();
return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
}
void Cell::setPreviousCell(Cell* c) {
return m_cell->setPreviousCell(c->m_cell);
}
void Cell::setNextCell(Cell* c) {
return m_cell->setNextCell(c->m_cell);
}
const TQString Cell::name() const {
return m_cell->name();
}
const TQString Cell::fullName() const {
return m_cell->fullName();
}
const TQString Cell::comment() const {
return m_cell->format()->comment(m_col, m_row);
}
void Cell::setComment(const TQString& c) {
return m_cell->format()->setComment(c);
}
const TQString Cell::getFormatString() const {
return m_cell->format()->getFormatString(m_col, m_row);
}
void Cell::setFormatString(const TQString& format) {
m_cell->format()->setFormatString(format);
}
const TQString Cell::text() const {
return m_cell->text();
}
bool Cell::setText(const TQString& text) {
KSpread::ProtectedCheck prot;
prot.setSheet (m_sheet);
prot.add (TQPoint (m_col, m_row));
if (prot.check())
return false;
KSpread::DataManipulator *dm = new KSpread::DataManipulator ();
dm->setSheet (m_sheet);
dm->setValue (text);
dm->setParsing (true);
dm->add (TQPoint (m_col, m_row));
dm->execute ();
return true;
}
const TQString Cell::textColor() {
return m_cell->format()->textColor(m_col, m_row).name();
}
void Cell::setTextColor(const TQString& textcolor) {
m_cell->format()->setTextColor( TQColor(textcolor) );
}
const TQString Cell::backgroundColor() {
return m_cell->format()->bgColor(m_col, m_row).name();
}
void Cell::setBackgroundColor(const TQString& backgroundcolor) {
m_cell->format()->setBgColor( TQColor(backgroundcolor) );
}
}
}
|