1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <rtl/string.hxx>
23 #include <rtl/ustring.hxx>
24 #include <tools/color.hxx>
26 #include "xerecord.hxx"
28 #include "excdefs.hxx"
30 //------------------------------------------------------------------ Forwards -
35 //----------------------------------------------------------- class ExcRecord -
37 class ExcRecord
: public XclExpRecord
40 virtual void Save( XclExpStream
& rStrm
) override
;
41 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
43 virtual sal_uInt16
GetNum() const = 0;
44 virtual std::size_t GetLen() const = 0;
47 virtual void SaveCont( XclExpStream
& rStrm
);
50 /** Writes the body of the record. */
51 virtual void WriteBody( XclExpStream
& rStrm
) override
;
54 //--------------------------------------------------------- class ExcEmptyRec -
56 class ExcEmptyRec
: public ExcRecord
61 virtual void Save( XclExpStream
& rStrm
) override
;
62 virtual sal_uInt16
GetNum() const override
;
63 virtual std::size_t GetLen() const override
;
66 //--------------------------------------------------------- class ExcDummyRec -
68 class ExcDummyRec
: public ExcRecord
72 virtual void Save( XclExpStream
& rStrm
) override
;
73 virtual sal_uInt16
GetNum() const override
;
74 virtual const sal_uInt8
* GetData() const = 0; // byte data must contain header and body
77 //------------------------------------------------------- class ExcBoolRecord -
78 // stores bool as 16bit val ( 0x0000 | 0x0001 )
80 class ExcBoolRecord
: public ExcRecord
83 virtual void SaveCont( XclExpStream
& rStrm
) override
;
88 ExcBoolRecord() : bVal( false ) {}
91 virtual std::size_t GetLen() const override
;
94 //--------------------------------------------------------- class ExcBof_Base -
96 class ExcBof_Base
: public ExcRecord
102 sal_uInt16 nRupBuild
;
108 //-------------------------------------------------------------- class ExcBof -
109 // Header Record for WORKSHEETS
111 class ExcBof
: public ExcBof_Base
114 virtual void SaveCont( XclExpStream
& rStrm
) override
;
118 virtual sal_uInt16
GetNum() const override
;
119 virtual std::size_t GetLen() const override
;
122 //------------------------------------------------------------- class ExcBofW -
123 // Header Record for WORKBOOKS
125 class ExcBofW
: public ExcBof_Base
128 virtual void SaveCont( XclExpStream
& rStrm
) override
;
132 virtual sal_uInt16
GetNum() const override
;
133 virtual std::size_t GetLen() const override
;
136 //-------------------------------------------------------------- class ExcEof -
138 class ExcEof
: public ExcRecord
142 virtual sal_uInt16
GetNum() const override
;
143 virtual std::size_t GetLen() const override
;
146 //--------------------------------------------------------- class ExcDummy_00 -
147 // INTERFACEHDR to FNGROUPCOUNT (see excrecds.cxx)
149 class ExcDummy_00
: public ExcDummyRec
152 static const sal_uInt8 pMyData
[];
153 static const std::size_t nMyLen
;
155 virtual std::size_t GetLen() const override
;
156 virtual const sal_uInt8
* GetData() const override
;
159 // EXC_ID_WINDOWPROTECTION
160 class XclExpWindowProtection
: public XclExpBoolRecord
163 XclExpWindowProtection(bool bValue
);
165 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
168 // EXC_ID_PROTECT Document Protection
169 class XclExpProtection
: public XclExpBoolRecord
172 XclExpProtection(bool bValue
);
175 class XclExpSheetProtection
: public XclExpProtection
179 XclExpSheetProtection(bool bValue
, SCTAB nTab
);
180 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
183 class XclExpPassHash
: public XclExpRecord
186 XclExpPassHash(const css::uno::Sequence
<sal_Int8
>& aHash
);
187 virtual ~XclExpPassHash() override
;
190 virtual void WriteBody(XclExpStream
& rStrm
) override
;
196 //-------------------------------------------------------- class ExcDummy_04x -
197 // PASSWORD to BOOKBOOL (see excrecds.cxx), no 1904
199 class ExcDummy_040
: public ExcDummyRec
202 static const sal_uInt8 pMyData
[];
203 static const std::size_t nMyLen
;
205 virtual std::size_t GetLen() const override
;
206 virtual const sal_uInt8
* GetData() const override
;
209 class ExcDummy_041
: public ExcDummyRec
212 static const sal_uInt8 pMyData
[];
213 static const std::size_t nMyLen
;
215 virtual std::size_t GetLen() const override
;
216 virtual const sal_uInt8
* GetData() const override
;
219 //------------------------------------------------------------- class Exc1904 -
221 class Exc1904
: public ExcBoolRecord
224 Exc1904( const ScDocument
& rDoc
);
225 virtual sal_uInt16
GetNum() const override
;
227 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
229 bool bDateCompatibility
;
232 //------------------------------------------------------ class ExcBundlesheet -
234 class ExcBundlesheetBase
: public ExcRecord
237 sal_uInt64 m_nStrPos
;
238 sal_uInt64 m_nOwnPos
; // Position after # and Len
242 ExcBundlesheetBase();
245 ExcBundlesheetBase( const RootData
& rRootData
, SCTAB nTab
);
247 void SetStreamPos(sal_uInt64
const nStrPos
) { m_nStrPos
= nStrPos
; }
248 void UpdateStreamPos( XclExpStream
& rStrm
);
250 virtual sal_uInt16
GetNum() const override
;
253 class ExcBundlesheet
: public ExcBundlesheetBase
258 virtual void SaveCont( XclExpStream
& rStrm
) override
;
261 ExcBundlesheet( const RootData
& rRootData
, SCTAB nTab
);
262 virtual std::size_t GetLen() const override
;
265 //--------------------------------------------------------- class ExcDummy_02 -
266 // sheet dummies: CALCMODE to SETUP
268 class ExcDummy_02a
: public ExcDummyRec
271 static const sal_uInt8 pMyData
[];
272 static const std::size_t nMyLen
;
274 virtual std::size_t GetLen() const override
;
275 virtual const sal_uInt8
* GetData() const override
;
278 /** This record contains the Windows country IDs for the UI and document language. */
279 class XclExpCountry
: public XclExpRecord
282 explicit XclExpCountry( const XclExpRoot
& rRoot
);
285 sal_uInt16 mnUICountry
; /// The UI country ID.
286 sal_uInt16 mnDocCountry
; /// The document country ID.
288 /** Writes the body of the COUNTRY record. */
289 virtual void WriteBody( XclExpStream
& rStrm
) override
;
292 // XclExpWsbool ===============================================================
294 class XclExpWsbool
: public XclExpUInt16Record
297 explicit XclExpWsbool( bool bFitToPages
);
301 * Save sheetPr element and its children for xlsx export.
303 class XclExpXmlSheetPr
: public XclExpRecordBase
306 explicit XclExpXmlSheetPr(
307 bool bFitToPages
, SCTAB nScTab
, const Color
& rTabColor
, XclExpFilterManager
* pManager
);
309 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
313 XclExpFilterManager
* mpManager
;
318 class XclExpFiltermode
: public XclExpEmptyRecord
321 explicit XclExpFiltermode();
324 class XclExpAutofilterinfo
: public XclExpUInt16Record
327 explicit XclExpAutofilterinfo( const ScAddress
& rStartPos
, SCCOL nScCol
);
329 const ScAddress
& GetStartPos() const { return maStartPos
; }
330 SCCOL
GetColCount() const { return static_cast< SCCOL
>( GetValue() ); }
333 ScAddress maStartPos
;
336 class ExcFilterCondition
341 std::unique_ptr
<XclExpString
>
346 ExcFilterCondition();
347 ~ExcFilterCondition();
349 bool IsEmpty() const { return (nType
== EXC_AFTYPE_NOTUSED
); }
350 std::size_t GetTextBytes() const;
352 void SetCondition( sal_uInt8 nTp
, sal_uInt8 nOp
, const OUString
* pT
);
354 void Save( XclExpStream
& rStrm
);
355 void SaveXml( XclExpXmlStream
& rStrm
);
356 void SaveText( XclExpStream
& rStrm
);
359 class XclExpAutofilter
: public XclExpRecord
, protected XclExpRoot
372 bool bIsButtonHidden
;
375 ExcFilterCondition aCond
[ 2 ];
376 std::vector
<std::pair
<OUString
, bool>> maMultiValues
; // first->values, second->bDateFormat
377 std::vector
<std::pair
<::Color
, bool>> maColorValues
; // first->Color, second->bIsBackgroundColor (vs. TextColor)
379 bool AddCondition( ScQueryConnect eConn
, sal_uInt8 nType
,
380 sal_uInt8 nOp
, const OUString
* pText
, bool bSimple
= false );
382 virtual void WriteBody( XclExpStream
& rStrm
) override
;
385 XclExpAutofilter( const XclExpRoot
& rRoot
, sal_uInt16 nC
, bool bIsEmpty
= false );
387 sal_uInt16
GetCol() const { return nCol
; }
388 bool HasTop10() const { return ::get_flag( nFlags
, EXC_AFFLAG_TOP10
); }
390 bool HasCondition() const;
391 bool AddEntry( const ScQueryEntry
& rEntry
);
392 void AddMultiValueEntry( const ScQueryEntry
& rEntry
);
393 void SetButtonHidden(bool bValue
) { bIsButtonHidden
= bValue
; }
394 void AddColorEntry( const ScQueryEntry
& rEntry
);
396 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
399 class ExcAutoFilterRecs
: public XclExpRecordBase
, protected XclExpRoot
402 /** @param pDefinedData
403 If nullptr, obtain anonymous ScDBData from sheet nTab.
404 Else, use defined database range; used with XclExpTables.
406 explicit ExcAutoFilterRecs( const XclExpRoot
& rRoot
, SCTAB nTab
, const ScDBData
* pDefinedData
);
407 virtual ~ExcAutoFilterRecs() override
;
411 virtual void Save( XclExpStream
& rStrm
) override
;
412 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
414 bool HasFilterMode() const;
417 XclExpAutofilter
* GetByCol( SCCOL nCol
); // always 0-based
418 bool IsFiltered( SCCOL nCol
);
421 typedef XclExpRecordList
< XclExpAutofilter
> XclExpAutofilterList
;
422 typedef XclExpAutofilterList::RecordRefType XclExpAutofilterRef
;
424 XclExpAutofilterList maFilterList
;
425 rtl::Reference
<XclExpFiltermode
> m_pFilterMode
;
426 rtl::Reference
<XclExpAutofilterinfo
> m_pFilterInfo
;
430 ScRange maSortRef
; // sort area without headers
431 std::vector
< std::tuple
<ScRange
, OUString
, bool> > maSortCustomList
; // sorted column with list of sorted items
434 /** Sheet filter manager. Contains auto filters or advanced filters from all sheets. */
435 class XclExpFilterManager
: protected XclExpRoot
438 explicit XclExpFilterManager( const XclExpRoot
& rRoot
);
440 /** Creates the filter records for the specified sheet.
441 @descr Creates and inserts related built-in NAME records. Therefore this
442 function is called from the name buffer itself. */
443 void InitTabFilter( SCTAB nScTab
);
445 /** Returns a record object containing all filter records for the specified sheet. */
446 XclExpRecordRef
CreateRecord( SCTAB nScTab
);
448 /** Returns whether or not FilterMode is present */
449 bool HasFilterMode( SCTAB nScTab
);
452 using XclExpRoot::CreateRecord
;
454 typedef rtl::Reference
< ExcAutoFilterRecs
> XclExpTabFilterRef
;
455 typedef ::std::map
< SCTAB
, XclExpTabFilterRef
> XclExpTabFilterMap
;
457 XclExpTabFilterMap maFilterMap
;
460 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */