admin
2023-03-07 8b06b1cbf112d55307ea8a6efe711db4e7506d89
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * This file is part of xlslib -- A multiplatform, C/C++ library
 * for dynamic generation of Excel(TM) files.
 *
 * Copyright 2004 Yeico S. A. de C. V. All Rights Reserved.
 * Copyright 2008-2011 David Hoerl All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
#include "../xlslib/record.h"
#include "../xlslib/cell.h"
#include "../xlslib/globalrec.h"
 
using namespace xlslib_core;
 
cell_t::cell_t(CGlobalRecords& gRecord, unsigned32_t rowNum, unsigned32_t colNum, xf_t* pxfval) :
    m_GlobalRecords(gRecord),
    pxf(pxfval ? pxfval : gRecord.GetDefaultXF()),
    row(rowNum), col(colNum)
{
    XL_ASSERT(pxf);
    pxf->MarkUsed();
 
    //cerr << "INITIAL XFT" << endl << pxf->Description() << endl;
}
 
cell_t::~cell_t()
{
    pxf->UnMarkUsed();
}
 
unsigned16_t cell_t::GetXFIndex() const
{
    XL_ASSERT(pxf);
    //return pxf ? pxf->GetIndex() : XF_PROP_XF_DEFAULT_CELL;
    return pxf->GetIndex();
}
 
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Implementation of the XF record interface (xf_i pure virtual interface)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
// This is why the default formats get marked used twice! (see test for > 1)
 
void cell_t::set_xf_common(void)
{
    if(pxf->Usage() > 1) {
        /* not sole user    */
        pxf->UnMarkUsed();
        pxf = xf_t::xfDup(pxf);
        pxf->MarkUsed();
    }
}
 
void cell_t::borderstyle(border_side_t side, border_style_t style)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetBorderStyle(side, style);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::bordercolor(border_side_t side, color_name_t color)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetBorderColor(side, color);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::bordercolor(border_side_t side, unsigned8_t color)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetBorderColor(side, color);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::font(font_t* fnt)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFont(fnt);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::format(format_number_t formatidx)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFormat(formatidx);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::format(format_t* fmt)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFormat(fmt);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::halign(halign_option_t ha_option)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetHAlign(ha_option);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::valign(valign_option_t va_option)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetVAlign(va_option);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::indent(indent_option_t indent_option)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetIndent(indent_option);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::orientation(txtori_option_t ori_option)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetTxtOrientation(ori_option);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::fillfgcolor(color_name_t color)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFillFGColor(color);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::fillfgcolor(unsigned8_t color)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFillFGColor(color);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::fillbgcolor(color_name_t color)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFillBGColor(color);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::fillbgcolor(unsigned8_t color)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFillBGColor(color);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::fillstyle(fill_option_t fill)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetFillStyle(fill);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::locked(bool locked_opt)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetLocked(locked_opt);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::hidden(bool hidden_opt)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetHidden(hidden_opt);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::wrap(bool wrap_opt)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    tempXF->SetWrap(wrap_opt);
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Implementation of the FONT record interface (font_i pure virtual interface)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
void cell_t::set_cell_font(void)
{
    xf_t * tempXF = xf_t::xfDup(pxf);
 
    font_t* currentfont = tempXF->GetFont();
 
    if(currentfont == NULL)    {
        currentfont = m_GlobalRecords.GetDefaultFont();
        font_t* fntnew = font_t::fontDup(currentfont);
        tempXF->SetFont(fntnew);
    } else
    if(currentfont->Usage() > 1) {
        font_t* fntnew = font_t::fontDup(currentfont);
        tempXF->SetFont(fntnew);
    }
 
       pxf->UnMarkUsed();
    pxf = m_GlobalRecords.findXF(tempXF);
    pxf->MarkUsed();
}
 
void cell_t::fontname(const std::string& fntname)
{
    set_cell_font();
    pxf->GetFont()->SetName(fntname);
}
 
void cell_t::fontheight(unsigned16_t fntheight)
{
    set_cell_font();
    pxf->GetFont()->SetHeight(fntheight);
}
 
void cell_t::fontbold(boldness_option_t fntboldness)
{
    set_cell_font();
    pxf->GetFont()->SetBoldStyle(fntboldness);
}
 
void cell_t::fontunderline(underline_option_t fntunderline)
{
    set_cell_font();
    pxf->GetFont()->SetUnderlineStyle(fntunderline);
}
 
void cell_t::fontscript(script_option_t fntscript)
{
    set_cell_font();
    pxf->GetFont()->SetScriptStyle(fntscript);
}
 
void cell_t::fontcolor(color_name_t fntcolor)
{
    set_cell_font();
    pxf->GetFont()->SetColor(fntcolor);
}
 
void cell_t::fontcolor(unsigned8_t fntcolor)
{
    set_cell_font();
    pxf->GetFont()->SetColor(fntcolor);
}
 
#if defined(DEPRECATED)
void cell_t::fontattr(unsigned16_t attr)
{
    set_cell_font();
    pxf->GetFont()->SetAttributes(attr);
}
 
#endif
 
void cell_t::fontitalic(bool italic)
{
    set_cell_font();
    pxf->GetFont()->SetItalic(italic);
}
 
void cell_t::fontstrikeout(bool so)
{
    set_cell_font();
    pxf->GetFont()->SetStrikeout(so);
}
 
void cell_t::fontoutline(bool ol)
{
    set_cell_font();
    pxf->GetFont()->SetOutline(ol);
}
 
void cell_t::fontshadow(bool sh)
{
    set_cell_font();
    pxf->GetFont()->SetShadow(sh);
}
 
void cell_t::SetXF(xf_t* pxfval)
{
    if(!pxfval) {return; }
 
    XL_ASSERT(pxf);
    pxfval->MarkUsed();
    pxf->UnMarkUsed();
    pxf = pxfval;
}
 
xf_t* cell_t::GetXF(void) const {return pxf; }