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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * 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-2013 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/colors.h"
#include "../xlslib/recdef.h"
#include "../xlslib/datast.h"
#include "../xlslib/rectypes.h"
 
 
using namespace xlslib_core;
using namespace xlslib_strings;
 
boundsheet_t::boundsheet_t(CGlobalRecords& gRecords) :
    sheetname(),
    streampos(0),
    notes(0),
    sheetData(NULL),
    m_GlobalRecords(gRecords)
{
    SetAttributes(0);
}
 
boundsheet_t::boundsheet_t(CGlobalRecords& gRecords, const u16string& sn, unsigned16_t attributes, unsigned32_t sp) :
    sheetname(sn),
    streampos(sp),
    notes(0),
    sheetData(NULL),
    m_GlobalRecords(gRecords)
{
    SetAttributes(attributes);
}
 
boundsheet_t::~boundsheet_t()
{
}
 
void boundsheet_t::SetAttributes(unsigned16_t attributes)
{
    worksheet = ((attributes & BSHEET_ATTR_WORKSHEET) == BSHEET_ATTR_WORKSHEET);
    ex4macro = ((attributes & BSHEET_ATTR_EX4MACRO) == BSHEET_ATTR_EX4MACRO);
    chart = ((attributes & BSHEET_ATTR_CHART) == BSHEET_ATTR_CHART);
    vbmodule = ((attributes & BSHEET_ATTR_VBMODULE) == BSHEET_ATTR_VBMODULE);
    visible = ((attributes & BSHEET_ATTR_VISIBLE) == BSHEET_ATTR_VISIBLE);
    hidden = ((attributes & BSHEET_ATTR_HIDDEN) == BSHEET_ATTR_HIDDEN);
    veryhidden = ((attributes & BSHEET_ATTR_VERYHIDDEN) == BSHEET_ATTR_VERYHIDDEN);
}
 
boundsheet_t::boundsheet_t(const boundsheet_t& that) :
    sheetname(that.sheetname),
    streampos(that.streampos),
    worksheet(that.worksheet),
    ex4macro(that.ex4macro),
    chart(that.chart),
    vbmodule(that.vbmodule),
    visible(that.visible),
    hidden(that.hidden),
    veryhidden(that.veryhidden),
    notes(that.notes),
    sheetData(that.sheetData),
    m_GlobalRecords(that.m_GlobalRecords)
{
}
 
boundsheet_t& boundsheet_t::operator=(const boundsheet_t& right)
{
    (void)right; // stop warning
    throw std::string("Should never have invoked the boundsheet_t copy operator!");
}
 
void boundsheet_t::SetSheetStreamPosition(size_t offset)
{
    sheetData->SetStreamPosition(offset);
}
 
/*
 ******************************
 * CBof class implementation
 ******************************
 */
CBof::CBof(CDataStorage &datastore, unsigned16_t boftype) :
    CRecord(datastore)
{
    SetRecordType(RECTYPE_BOF);
 
    AddValue16(VERSION_BIFF);
    AddValue16(boftype);
    AddValue16(BOF_BUILD_DFLT);
    AddValue16(BOF_YEAR_DFLT);
 
    AddValue32(0);                  // The file history flags are all set to zero
    AddValue32(VERSION_BIFF);       // The lowest BIFF version
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CBof::~CBof()
{}
 
/*
 ******************************
 * CEof class implementation
 ******************************
 */
CEof::CEof(CDataStorage &datastore) :
    CRecord(datastore)
{
    SetRecordType(RECTYPE_EOF);
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CEof::~CEof()
{
}
 
/*
 **********************************
 *  CCodePage class implementation
 **********************************
 */
CCodePage::CCodePage(CDataStorage &datastore, unsigned16_t boftype) :
    CRecord(datastore)
{
    SetRecordType(RECTYPE_CODENAME);
 
    AddValue16(boftype);
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CCodePage::~CCodePage()
{}
 
/*
 **********************************
 *  window1 class implementation
 **********************************
 */
window1::window1() :
    horzPos(0), vertPos(0),
    windWidth(0x37e0/TWIP), windHeight(0x25e0/TWIP),
    activeSheet(0),
    firstVisibleTab(0),
    tabBarWidth(500)
{
}
 
window1::~window1()
{
}
 
/*
 **********************************
 *  CWindow1 class implementation
 **********************************
 */
CWindow1::CWindow1(CDataStorage &datastore, const window1& wind1) :
    CRecord(datastore)
{
    SetRecordType(RECTYPE_WINDOW1);
 
    AddValue16(wind1.horzPos*TWIP);
    AddValue16(wind1.vertPos*TWIP);
    AddValue16(wind1.windWidth*TWIP);
    AddValue16(wind1.windHeight*TWIP);
    AddValue16(0x0038);                 // FLAGS: tabBar, vertScroller, horzScroller
    AddValue16(wind1.activeSheet);
    AddValue16(wind1.firstVisibleTab);      // only useful for when you have so many tabs the tab scroller is active
    AddValue16(1);                      // number of selected sheets
    AddValue16(wind1.tabBarWidth);
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CWindow1::~CWindow1()
{
}
 
/*
 **********************************
 *  CDateMode class implementation
 **********************************
 */
 
CDateMode::CDateMode(CDataStorage &datastore) :
    CRecord(datastore)
{
    SetRecordType(RECTYPE_DATEMODE);
 
    AddValue16(Is_In_1904_Mode() ? 1 : 0);
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CDateMode::~CDateMode()
{}
 
 
bool CDateMode::Is_In_1904_Mode(void)
{
#ifdef __APPLE__
    return true; // 1904  [i_a]
 
#else
    return false;   // 1900
 
#endif
}
 
/*
 **********************************
 *  CWindow2 class implementation
 **********************************
 */
CWindow2::CWindow2(CDataStorage &datastore, bool isActive) :
    CRecord(datastore)
{
    unsigned16_t flags;
 
    SetRecordType(RECTYPE_WINDOW2);
 
    flags =    W2_GRBITMASK_GUTS|W2_GRBITMASK_DFLTHDRCOLOR|W2_GRBITMASK_ZEROS|     // 0x00B0
        W2_GRBITMASK_HROWCOL|W2_GRBITMASK_FROZEN|W2_GRBITMASK_GRIDS;            // 0x000E
    if(isActive) {
        flags |= W2_GRBITMASK_ACTIVE|W2_GRBITMASK_SELECTED;
    }
 
    AddValue16(flags);
    AddValue16(W2_DFLT_TOPROW);
    AddValue16(W2_DFLT_LEFTCOL);
 
    AddValue16(COLOR_CODE_SYS_WIND_FG); // grid color
    AddValue16(0);                      // UNUSED
    AddValue16(0);                      // zoom page break preview, default == 0 (W2_DFLT_ZOOMPBPREV ???)
    AddValue16(0);                      // zoom normal view, default == 0 (W2_DFLT_ZOOMNORMAL ???)
    AddValue32(W2_DFLT_RESERVED);
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CWindow2::~CWindow2()
{
}
 
/*
 **********************************
 *  CDimension class implementation
 **********************************
 */
CDimension::CDimension(CDataStorage &datastore,
                       unsigned32_t minRow,
                       unsigned32_t maxRow,
                       unsigned32_t minCol,
                       unsigned32_t maxCol) :
    CRecord(datastore)
{
    SetRecordType(RECTYPE_DIMENSIONS);
 
    AddValue32(minRow);
    AddValue32(maxRow+1);
    AddValue16((unsigned16_t)minCol);
    AddValue16((unsigned16_t)(maxCol+1));                       // zoom, default == 0 (W2_DFLT_ZOOMPBPREV ???)
    AddValue16(W2_DFLT_RESERVED);
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CDimension::~CDimension()
{
}
 
void CWindow2::SetSelected()
{
    unsigned16_t grbitval;
 
    GetValue16From(&grbitval, W2_OFFSET_GRBIT);
 
    grbitval |= W2_GRBITMASK_SELECTED;
 
    SetValueAt16(grbitval, W2_OFFSET_GRBIT);
}
 
void CWindow2::SetPaged()
{
    unsigned16_t grbitval;
 
    GetValue16From(&grbitval, W2_OFFSET_GRBIT);
 
    grbitval |= W2_GRBITMASK_PAGEBRK;
 
    SetValueAt16(grbitval, W2_OFFSET_GRBIT);
}
 
void CWindow2::ClearSelected()
{
    unsigned16_t grbitval;
 
    GetValue16From(&grbitval, W2_OFFSET_GRBIT);
 
    grbitval &= ~W2_GRBITMASK_SELECTED;
 
    SetValueAt16(grbitval, W2_OFFSET_GRBIT);
}
 
void CWindow2::ClearPaged()
{
    unsigned16_t grbitval;
 
    GetValue16From(&grbitval, W2_OFFSET_GRBIT);
 
    grbitval &= W2_GRBITMASK_PAGEBRK;
 
    SetValueAt16(grbitval, W2_OFFSET_GRBIT);
}
 
/*
 ******************************
 * CStyle class implementation
 ******************************
 */
#define STYLE_BUILTIN_NORMAL      ((unsigned8_t)0x00)
#define STYLE_BUILTIN_ROWLEVELN   ((unsigned8_t)0x01)
#define STYLE_BUILTIN_COLLEVELN   ((unsigned8_t)0x02)
#define STYLE_BUILTIN_COMMA       ((unsigned8_t)0x03)
#define STYLE_BUILTIN_CURRENCY    ((unsigned8_t)0x04)
#define STYLE_BUILTIN_PERCENT     ((unsigned8_t)0x05)
#define STYLE_BUILTIN_COMMAT      ((unsigned8_t)0x06)
#define STYLE_BUILTIN_CURRENCYT   ((unsigned8_t)0x07)
 
#define STYLE_BUILTIN_BIT   ((unsigned16_t)0x8000)
 
//#define STYLE_LEVEL_DUMMY         ((unsigned8_t)0x00)
 
CStyle::CStyle(CDataStorage &datastore, const style_t* styledef) :
    CRecord(datastore)
{
    // TODO: Implement user-defined styles. So far only built-in are used.
    SetRecordType(RECTYPE_STYLE);
 
    AddValue16(styledef->xfindex|STYLE_BUILTIN_BIT);
    AddValue8(styledef->builtintype);
    AddValue8(styledef->level);
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CStyle::~CStyle()
{
}
 
/*
 ******************************
 * CBSheet class implementation
 ******************************
 */
CBSheet::CBSheet(CDataStorage &datastore, const boundsheet_t* bsheetdef) :
    CRecord(datastore)
{
    m_Backpatching_Level = 3;
 
    SetRecordType(RECTYPE_BOUNDSHEET);
    AddValue32(bsheetdef->GetStreamPos());
 
    // Set the flags in the attribute variables
    unsigned16_t attrflags = 0;
    // attrflags |= (bsheetdef->IsWorkSheet()    ? BSHEET_ATTR_WORKSHEET:0); // has no affect
    attrflags |= (bsheetdef->IsEx4macro()    ? BSHEET_ATTR_EX4MACRO : 0);
    attrflags |= (bsheetdef->IsChart()        ? BSHEET_ATTR_CHART : 0);
    attrflags |= (bsheetdef->IsVBModule()    ? BSHEET_ATTR_VBMODULE : 0);
    attrflags |= (bsheetdef->IsVisible()    ? BSHEET_ATTR_VISIBLE : BSHEET_ATTR_HIDDEN);
    attrflags |= (bsheetdef->IsHidden()        ? BSHEET_ATTR_HIDDEN : 0);
    attrflags |= (bsheetdef->IsVeryHidden()    ? BSHEET_ATTR_VERYHIDDEN : 0);
 
    AddValue16(attrflags);
    AddUnicodeString(bsheetdef->GetSheetName(), LEN1_FLAGS_UNICODE);
 
    SetRecordLength(GetDataSize()-RECORD_HEADER_SIZE);
}
 
CBSheet::~CBSheet()
{
}
 
void CBSheet::SetStreamPosition(size_t pos)
{
    SetValueAt32((unsigned32_t)pos, BSHEET_OFFSET_POSITION);
}