summaryrefslogtreecommitdiffstats
path: root/sc/source/filter/inc/excrecds.hxx
blob: a0abbf9410cde3eca471dbca5dc96b8f264aa66a (plain)
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SC_SOURCE_FILTER_INC_EXCRECDS_HXX
#define INCLUDED_SC_SOURCE_FILTER_INC_EXCRECDS_HXX

#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#include <tools/color.hxx>

#include "xerecord.hxx"
#include "xeroot.hxx"
#include "excdefs.hxx"

//------------------------------------------------------------------ Forwards -

class ScDBData;
struct ScQueryEntry;

//----------------------------------------------------------- class ExcRecord -

class ExcRecord : public XclExpRecord
{
public:
    virtual void            Save( XclExpStream& rStrm ) override;
    virtual void            SaveXml( XclExpXmlStream& rStrm ) override;

    virtual sal_uInt16          GetNum() const = 0;
    virtual std::size_t     GetLen() const = 0;

protected:
    virtual void            SaveCont( XclExpStream& rStrm );

private:
    /** Writes the body of the record. */
    virtual void            WriteBody( XclExpStream& rStrm ) override;
};

//--------------------------------------------------------- class ExcEmptyRec -

class ExcEmptyRec : public ExcRecord
{
private:
protected:
public:
    virtual void            Save( XclExpStream& rStrm ) override;
    virtual sal_uInt16          GetNum() const override;
    virtual std::size_t     GetLen() const override;
};

//--------------------------------------------------------- class ExcDummyRec -

class ExcDummyRec : public ExcRecord
{
protected:
public:
    virtual void            Save( XclExpStream& rStrm ) override;
    virtual sal_uInt16          GetNum() const override;
    virtual const sal_uInt8*        GetData() const = 0;    // byte data must contain header and body
};

//------------------------------------------------------- class ExcBoolRecord -
// stores bool as 16bit val ( 0x0000 | 0x0001 )

class ExcBoolRecord : public ExcRecord
{
private:
    virtual void            SaveCont( XclExpStream& rStrm ) override;

protected:
    bool                    bVal;

    ExcBoolRecord() : bVal( false ) {}

public:
    virtual std::size_t     GetLen() const override;
};

//--------------------------------------------------------- class ExcBof_Base -

class ExcBof_Base : public ExcRecord
{
private:
protected:
    sal_uInt16                  nDocType;
    sal_uInt16                  nVers;
    sal_uInt16                  nRupBuild;
    sal_uInt16                  nRupYear;
public:
                            ExcBof_Base();
};

//-------------------------------------------------------------- class ExcBof -
// Header Record for WORKSHEETS

class ExcBof : public ExcBof_Base
{
private:
    virtual void            SaveCont( XclExpStream& rStrm ) override;
public:
                            ExcBof();

    virtual sal_uInt16          GetNum() const override;
    virtual std::size_t     GetLen() const override;
};

//------------------------------------------------------------- class ExcBofW -
// Header Record for WORKBOOKS

class ExcBofW : public ExcBof_Base
{
private:
    virtual void            SaveCont( XclExpStream& rStrm ) override;
public:
                            ExcBofW();

    virtual sal_uInt16          GetNum() const override;
    virtual std::size_t     GetLen() const override;
};

//-------------------------------------------------------------- class ExcEof -

class ExcEof : public ExcRecord
{
private:
public:
    virtual sal_uInt16          GetNum() const override;
    virtual std::size_t     GetLen() const override;
};

//--------------------------------------------------------- class ExcDummy_00 -
// INTERFACEHDR to FNGROUPCOUNT (see excrecds.cxx)

class ExcDummy_00 : public ExcDummyRec
{
private:
    static const sal_uInt8      pMyData[];
    static const std::size_t   nMyLen;
public:
    virtual std::size_t        GetLen() const override;
    virtual const sal_uInt8*        GetData() const override;
};

// EXC_ID_WINDOWPROTECTION
class XclExpWindowProtection : public   XclExpBoolRecord
{
    public:
        XclExpWindowProtection(bool bValue);

    virtual void            SaveXml( XclExpXmlStream& rStrm ) override;
};

// EXC_ID_PROTECT  Document Protection
class XclExpProtection : public XclExpBoolRecord
{
    public:
        XclExpProtection(bool bValue);
};

class XclExpSheetProtection : public XclExpProtection
{
    SCTAB const             mnTab;
    public:
        XclExpSheetProtection(bool bValue, SCTAB nTab);
    virtual void            SaveXml( XclExpXmlStream& rStrm ) override;
};

class XclExpPassHash : public XclExpRecord
{
public:
    XclExpPassHash(const css::uno::Sequence<sal_Int8>& aHash);
    virtual ~XclExpPassHash() override;

private:
    virtual void    WriteBody(XclExpStream& rStrm) override;

private:
    sal_uInt16  mnHash;
};

//-------------------------------------------------------- class ExcDummy_04x -
// PASSWORD to BOOKBOOL (see excrecds.cxx), no 1904

class ExcDummy_040 : public ExcDummyRec
{
private:
    static const sal_uInt8      pMyData[];
    static const std::size_t   nMyLen;
public:
    virtual std::size_t        GetLen() const override;
    virtual const sal_uInt8*        GetData() const override;
};

class ExcDummy_041 : public ExcDummyRec
{
private:
    static const sal_uInt8     pMyData[];
    static const std::size_t   nMyLen;
public:
    virtual std::size_t        GetLen() const override;
    virtual const sal_uInt8*   GetData() const override;
};

//------------------------------------------------------------- class Exc1904 -

class Exc1904 : public ExcBoolRecord
{
public:
                            Exc1904( const ScDocument& rDoc );
    virtual sal_uInt16      GetNum() const override;

    virtual void            SaveXml( XclExpXmlStream& rStrm ) override;
private:
    bool                    bDateCompatibility;
};

//------------------------------------------------------ class ExcBundlesheet -

class ExcBundlesheetBase : public ExcRecord
{
protected:
    sal_uInt64              m_nStrPos;
    sal_uInt64              m_nOwnPos;    // Position after # and Len
    sal_uInt16              nGrbit;
    SCTAB const             nTab;

                            ExcBundlesheetBase();

public:
                            ExcBundlesheetBase( const RootData& rRootData, SCTAB nTab );

    void                    SetStreamPos(sal_uInt64 const nStrPos) { m_nStrPos = nStrPos; }
    void                    UpdateStreamPos( XclExpStream& rStrm );

    virtual sal_uInt16          GetNum() const override;
};

class ExcBundlesheet : public ExcBundlesheetBase
{
private:
    OString            aName;

    virtual void            SaveCont( XclExpStream& rStrm ) override;

public:
                            ExcBundlesheet( const RootData& rRootData, SCTAB nTab );
    virtual std::size_t     GetLen() const override;
};

//--------------------------------------------------------- class ExcDummy_02 -
// sheet dummies: CALCMODE to SETUP

class ExcDummy_02a : public ExcDummyRec
{
private:
    static const sal_uInt8      pMyData[];
    static const std::size_t   nMyLen;
public:
    virtual std::size_t        GetLen() const override;
    virtual const sal_uInt8*        GetData() const override;
};

/** This record contains the Windows country IDs for the UI and document language. */
class XclExpCountry : public XclExpRecord
{
public:
    explicit                    XclExpCountry( const XclExpRoot& rRoot );

private:
    sal_uInt16                  mnUICountry;        /// The UI country ID.
    sal_uInt16                  mnDocCountry;       /// The document country ID.

    /** Writes the body of the COUNTRY record. */
    virtual void                WriteBody( XclExpStream& rStrm ) override;
};

// XclExpWsbool ===============================================================

class XclExpWsbool : public XclExpUInt16Record
{
public:
    explicit XclExpWsbool( bool bFitToPages );
};

/**
 * Save sheetPr element and its children for xlsx export.
 */
class XclExpXmlSheetPr : public XclExpRecordBase
{
public:
    explicit XclExpXmlSheetPr(
        bool bFitToPages, SCTAB nScTab, const Color& rTabColor, XclExpFilterManager* pManager );

    virtual void SaveXml( XclExpXmlStream& rStrm ) override;

private:
    SCTAB const mnScTab;
    XclExpFilterManager* mpManager;
    bool const mbFitToPage;
    Color const maTabColor;
};

class XclExpFiltermode : public XclExpEmptyRecord
{
public:
    explicit            XclExpFiltermode();
};

class XclExpAutofilterinfo : public XclExpUInt16Record
{
public:
    explicit            XclExpAutofilterinfo( const ScAddress& rStartPos, SCCOL nScCol );

    const ScAddress& GetStartPos() const { return maStartPos; }
    SCCOL        GetColCount() const { return static_cast< SCCOL >( GetValue() ); }

private:
    ScAddress const         maStartPos;
};

class ExcFilterCondition
{
private:
    sal_uInt8               nType;
    sal_uInt8               nOper;
    double                  fVal;
    std::unique_ptr<XclExpString>
                            pText;

protected:
public:
                            ExcFilterCondition();
                            ~ExcFilterCondition();

    bool             IsEmpty() const     { return (nType == EXC_AFTYPE_NOTUSED); }
    std::size_t             GetTextBytes() const;

    void                    SetCondition( sal_uInt8 nTp, sal_uInt8 nOp, double fV, const OUString* pT );

    void                    Save( XclExpStream& rStrm );
    void                    SaveXml( XclExpXmlStream& rStrm );
    void                    SaveText( XclExpStream& rStrm );
};

class XclExpAutofilter : public XclExpRecord, protected XclExpRoot
{
private:
    enum FilterType { FilterCondition, MultiValue };
    FilterType              meType;
    sal_uInt16              nCol;
    sal_uInt16              nFlags;
    ExcFilterCondition      aCond[ 2 ];
    std::vector<OUString> maMultiValues;

    bool                    AddCondition( ScQueryConnect eConn, sal_uInt8 nType,
                                sal_uInt8 nOp, double fVal, const OUString* pText,
                                bool bSimple = false );

    virtual void            WriteBody( XclExpStream& rStrm ) override;

public:
                            XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC );

    sal_uInt16       GetCol() const          { return nCol; }
    bool             HasTop10() const        { return ::get_flag( nFlags, EXC_AFFLAG_TOP10 ); }

    bool                    HasCondition() const;
    bool                    AddEntry( const ScQueryEntry& rEntry );
    void                    AddMultiValueEntry( const ScQueryEntry& rEntry );

    virtual void            SaveXml( XclExpXmlStream& rStrm ) override;
};

class ExcAutoFilterRecs : public XclExpRecordBase, protected XclExpRoot
{
public:
    /** @param  pDefinedData
                If nullptr, obtain anonymous ScDBData from sheet nTab.
                Else, use defined database range; used with XclExpTables.
     */
    explicit            ExcAutoFilterRecs( const XclExpRoot& rRoot, SCTAB nTab, const ScDBData* pDefinedData );
    virtual             ~ExcAutoFilterRecs() override;

    void                AddObjRecs();

    virtual void        Save( XclExpStream& rStrm ) override;
    virtual void        SaveXml( XclExpXmlStream& rStrm ) override;

    bool                HasFilterMode() const;

private:
    XclExpAutofilter*   GetByCol( SCCOL nCol ); // always 0-based
    bool                IsFiltered( SCCOL nCol );

private:
    typedef XclExpRecordList< XclExpAutofilter >    XclExpAutofilterList;
    typedef XclExpAutofilterList::RecordRefType     XclExpAutofilterRef;

    XclExpAutofilterList maFilterList;
    std::unique_ptr<XclExpFiltermode> m_pFilterMode;
    std::unique_ptr<XclExpAutofilterinfo> m_pFilterInfo;
    ScRange                 maRef;
    bool mbAutoFilter;

    ScRange maSortRef; // sort area without headers
    std::vector< std::tuple<ScRange, OUString, bool> > maSortCustomList; // sorted column with list of sorted items
};

/** Sheet filter manager. Contains auto filters or advanced filters from all sheets. */
class XclExpFilterManager : protected XclExpRoot
{
public:
    explicit            XclExpFilterManager( const XclExpRoot& rRoot );

    /** Creates the filter records for the specified sheet.
        @descr  Creates and inserts related built-in NAME records. Therefore this
            function is called from the name buffer itself. */
    void                InitTabFilter( SCTAB nScTab );

    /** Returns a record object containing all filter records for the specified sheet. */
    XclExpRecordRef     CreateRecord( SCTAB nScTab );

    /** Returns whether or not FilterMode is present */
    bool                HasFilterMode( SCTAB nScTab );

private:
    using               XclExpRoot::CreateRecord;

    typedef std::shared_ptr< ExcAutoFilterRecs >  XclExpTabFilterRef;
    typedef ::std::map< SCTAB, XclExpTabFilterRef > XclExpTabFilterMap;

    XclExpTabFilterMap  maFilterMap;
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */