summaryrefslogtreecommitdiff
path: root/sc/source/filter/inc/xeroot.hxx
blob: 5a7ac4ef751ea8457293e0fae9bb3033196aaeb8 (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
/* -*- 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_XEROOT_HXX
#define INCLUDED_SC_SOURCE_FILTER_INC_XEROOT_HXX

#include <com/sun/star/beans/NamedValue.hpp>

#include "xlroot.hxx"
#include "compiler.hxx"
#include <memory>

// Forward declarations of objects in public use ==============================

class XclExpRecordBase;
class XclExpString;

typedef std::shared_ptr< XclExpRecordBase >  XclExpRecordRef;
typedef std::shared_ptr< XclExpString >      XclExpStringRef;

// Global data ================================================================

class XclExpTabInfo;
class XclExpAddressConverter;
class XclExpFormulaCompiler;
class XclExpProgressBar;
class XclExpSst;
class XclExpPalette;
class XclExpFontBuffer;
class XclExpNumFmtBuffer;
class XclExpXFBuffer;
class XclExpLinkManager;
class XclExpNameManager;
class XclExpObjectManager;
class XclExpFilterManager;
class XclExpPivotTableManager;
class XclExpDxfs;
class XclExpXmlPivotTableManager;
class XclExpTablesManager;
namespace sc { class CompileFormulaContext; }

/** Stores global buffers and data needed for Excel export filter. */
struct XclExpRootData : public XclRootData
{
    typedef std::shared_ptr< XclExpTabInfo >             XclExpTabInfoRef;
    typedef std::shared_ptr< XclExpAddressConverter >    XclExpAddrConvRef;
    typedef std::shared_ptr< XclExpFormulaCompiler >     XclExpFmlaCompRef;
    typedef std::shared_ptr< XclExpProgressBar >         XclExpProgressRef;

    typedef std::shared_ptr< XclExpSst >                 XclExpSstRef;
    typedef std::shared_ptr< XclExpPalette >             XclExpPaletteRef;
    typedef std::shared_ptr< XclExpFontBuffer >          XclExpFontBfrRef;
    typedef std::shared_ptr< XclExpNumFmtBuffer >        XclExpNumFmtBfrRef;
    typedef std::shared_ptr< XclExpXFBuffer >            XclExpXFBfrRef;
    typedef std::shared_ptr< XclExpNameManager >         XclExpNameMgrRef;
    typedef std::shared_ptr< XclExpLinkManager >         XclExpLinkMgrRef;
    typedef std::shared_ptr< XclExpObjectManager >       XclExpObjectMgrRef;
    typedef std::shared_ptr< XclExpFilterManager >       XclExpFilterMgrRef;
    typedef std::shared_ptr< XclExpPivotTableManager >   XclExpPTableMgrRef;
    typedef std::shared_ptr< XclExpDxfs >                XclExpDxfsRef;

    XclExpTabInfoRef    mxTabInfo;          /// Calc->Excel sheet index conversion.
    XclExpAddrConvRef   mxAddrConv;         /// The address converter.
    XclExpFmlaCompRef   mxFmlaComp;         /// The formula compiler.
    XclExpProgressRef   mxProgress;         /// The export progress bar.

    XclExpSstRef        mxSst;              /// The shared string table.
    XclExpPaletteRef    mxPalette;          /// The color buffer.
    XclExpFontBfrRef    mxFontBfr;          /// All fonts in the file.
    XclExpNumFmtBfrRef  mxNumFmtBfr;        /// All number formats in the file.
    XclExpXFBfrRef      mxXFBfr;            /// All XF records in the file.
    XclExpNameMgrRef    mxNameMgr;          /// Internal defined names.
    XclExpLinkMgrRef    mxGlobLinkMgr;      /// Global link manager for defined names.
    XclExpLinkMgrRef    mxLocLinkMgr;       /// Local link manager for a sheet.
    XclExpObjectMgrRef  mxObjMgr;           /// All drawing objects.
    XclExpFilterMgrRef  mxFilterMgr;        /// Manager for filtered areas in all sheets.
    XclExpPTableMgrRef  mxPTableMgr;        /// All pivot tables and pivot caches.
    XclExpDxfsRef       mxDxfs;             /// All delta formatting entries

    std::shared_ptr<XclExpXmlPivotTableManager> mxXmlPTableMgr;
    std::shared_ptr<XclExpTablesManager> mxTablesMgr;
    std::shared_ptr<sc::CompileFormulaContext> mpCompileFormulaCxt;

    ScCompiler::OpCodeMapPtr  mxOpCodeMap;  /// mapping between op-codes and names

    bool                mbRelUrl;           /// true = Store URLs relative.

    OStringBuffer       maStringBuf;        /// buffer to avoid massive OUString allocations

    explicit            XclExpRootData( XclBiff eBiff, SfxMedium& rMedium,
                            tools::SvRef<SotStorage> xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc );
    virtual             ~XclExpRootData() override;
};

/** Access to global data from other classes. */
class XclExpRoot : public XclRoot
{
public:
    explicit            XclExpRoot( XclExpRootData& rExpRootData );

    /** Returns this root instance - for code readability in derived classes. */
    inline const XclExpRoot& GetRoot() const { return *this; }
    /** Returns true, if URLs should be stored relative to the document location. */
    inline bool         IsRelUrl() const { return mrExpData.mbRelUrl; }
    sc::CompileFormulaContext& GetCompileFormulaContext() const { return *mrExpData.mpCompileFormulaCxt; }

    /** Returns the buffer for Calc->Excel sheet index conversion. */
    XclExpTabInfo&      GetTabInfo() const;
    /** Returns the address converter. */
    XclExpAddressConverter& GetAddressConverter() const;
    /** Returns the formula compiler to produce formula token arrays. */
    XclExpFormulaCompiler& GetFormulaCompiler() const;
    /** Returns the export progress bar. */
    XclExpProgressBar&  GetProgressBar() const;

    /** Returns the shared string table. */
    XclExpSst&          GetSst() const;
    /** Returns the color buffer. */
    XclExpPalette&      GetPalette() const;
    /** Returns the font buffer. */
    XclExpFontBuffer&   GetFontBuffer() const;
    /** Returns the number format buffer. */
    XclExpNumFmtBuffer& GetNumFmtBuffer() const;
    /** Returns the cell formatting attributes buffer. */
    XclExpXFBuffer&     GetXFBuffer() const;
    /** Returns the global link manager for defined names. */
    XclExpLinkManager&  GetGlobalLinkManager() const;
    /** Returns the local link manager for the current sheet. */
    XclExpLinkManager&  GetLocalLinkManager() const;
    /** Returns the buffer that contains internal defined names. */
    XclExpNameManager&  GetNameManager() const;
    /** Returns the drawing object manager. */
    XclExpObjectManager& GetObjectManager() const;
    /** Returns the filter manager. */
    XclExpFilterManager& GetFilterManager() const;
    /** Returns the pivot table manager. */
    XclExpPivotTableManager& GetPivotTableManager() const;
    /** Returns the differential formatting list */
    XclExpDxfs&          GetDxfs() const;

    /** Clean and return the OStringBuffer */
    inline OStringBuffer&   GetStringBuf() const { mrExpData.maStringBuf.setLength(0); return mrExpData.maStringBuf; }

    XclExpXmlPivotTableManager& GetXmlPivotTableManager();

    XclExpTablesManager& GetTablesManager();

    /** Is called when export filter starts to create the Excel document (all BIFF versions). */
    void                InitializeConvert();
    /** Is called when export filter starts to create the workbook global data (>=BIFF5). */
    void                InitializeGlobals();
    /** Is called when export filter starts to create data for a single sheet (all BIFF versions). */
    void                InitializeTable( SCTAB nScTab );
    /** Is called before export filter starts to write the records to the stream. */
    void                InitializeSave();
    /** Returns the reference to a record (or record list) representing a root object.
        @param nRecId  Identifier that specifies which record is returned. */
    XclExpRecordRef     CreateRecord( sal_uInt16 nRecId ) const;

    bool                IsDocumentEncrypted() const;

    static css::uno::Sequence< css::beans::NamedValue > GenerateEncryptionData( const OUString& aPass );
    css::uno::Sequence< css::beans::NamedValue > GetEncryptionData() const;
    css::uno::Sequence< css::beans::NamedValue > GenerateDefaultEncryptionData() const;

private:

    /** Returns the local or global link manager, depending on current context. */
    XclExpRootData::XclExpLinkMgrRef const & GetLocalLinkMgrRef() const;

private:
    XclExpRootData& mrExpData;      /// Reference to the global export data struct.
};

#endif

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