Get the style color and number just once
[LibreOffice.git] / sc / source / filter / inc / excrecds.hxx
blob629ddfd18b5ac3e7b9a126eadb21680413a933bd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <rtl/string.hxx>
23 #include <rtl/ustring.hxx>
24 #include <tools/color.hxx>
26 #include "xerecord.hxx"
27 #include "xeroot.hxx"
28 #include "excdefs.hxx"
30 //------------------------------------------------------------------ Forwards -
32 class ScDBData;
33 struct ScQueryEntry;
35 //----------------------------------------------------------- class ExcRecord -
37 class ExcRecord : public XclExpRecord
39 public:
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;
46 protected:
47 virtual void SaveCont( XclExpStream& rStrm );
49 private:
50 /** Writes the body of the record. */
51 virtual void WriteBody( XclExpStream& rStrm ) override;
54 //--------------------------------------------------------- class ExcEmptyRec -
56 class ExcEmptyRec : public ExcRecord
58 private:
59 protected:
60 public:
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
70 protected:
71 public:
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
82 private:
83 virtual void SaveCont( XclExpStream& rStrm ) override;
85 protected:
86 bool bVal;
88 ExcBoolRecord() : bVal( false ) {}
90 public:
91 virtual std::size_t GetLen() const override;
94 //--------------------------------------------------------- class ExcBof_Base -
96 class ExcBof_Base : public ExcRecord
98 private:
99 protected:
100 sal_uInt16 nDocType;
101 sal_uInt16 nVers;
102 sal_uInt16 nRupBuild;
103 sal_uInt16 nRupYear;
104 public:
105 ExcBof_Base();
108 //-------------------------------------------------------------- class ExcBof -
109 // Header Record for WORKSHEETS
111 class ExcBof : public ExcBof_Base
113 private:
114 virtual void SaveCont( XclExpStream& rStrm ) override;
115 public:
116 ExcBof();
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
127 private:
128 virtual void SaveCont( XclExpStream& rStrm ) override;
129 public:
130 ExcBofW();
132 virtual sal_uInt16 GetNum() const override;
133 virtual std::size_t GetLen() const override;
136 //-------------------------------------------------------------- class ExcEof -
138 class ExcEof : public ExcRecord
140 private:
141 public:
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
151 private:
152 static const sal_uInt8 pMyData[];
153 static const std::size_t nMyLen;
154 public:
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
162 public:
163 XclExpWindowProtection(bool bValue);
165 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
168 // EXC_ID_PROTECT Document Protection
169 class XclExpProtection : public XclExpBoolRecord
171 public:
172 XclExpProtection(bool bValue);
175 class XclExpSheetProtection : public XclExpProtection
177 SCTAB mnTab;
178 public:
179 XclExpSheetProtection(bool bValue, SCTAB nTab);
180 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
183 class XclExpPassHash : public XclExpRecord
185 public:
186 XclExpPassHash(const css::uno::Sequence<sal_Int8>& aHash);
187 virtual ~XclExpPassHash() override;
189 private:
190 virtual void WriteBody(XclExpStream& rStrm) override;
192 private:
193 sal_uInt16 mnHash;
196 //-------------------------------------------------------- class ExcDummy_04x -
197 // PASSWORD to BOOKBOOL (see excrecds.cxx), no 1904
199 class ExcDummy_040 : public ExcDummyRec
201 private:
202 static const sal_uInt8 pMyData[];
203 static const std::size_t nMyLen;
204 public:
205 virtual std::size_t GetLen() const override;
206 virtual const sal_uInt8* GetData() const override;
209 class ExcDummy_041 : public ExcDummyRec
211 private:
212 static const sal_uInt8 pMyData[];
213 static const std::size_t nMyLen;
214 public:
215 virtual std::size_t GetLen() const override;
216 virtual const sal_uInt8* GetData() const override;
219 //------------------------------------------------------------- class Exc1904 -
221 class Exc1904 : public ExcBoolRecord
223 public:
224 Exc1904( const ScDocument& rDoc );
225 virtual sal_uInt16 GetNum() const override;
227 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
228 private:
229 bool bDateCompatibility;
232 //------------------------------------------------------ class ExcBundlesheet -
234 class ExcBundlesheetBase : public ExcRecord
236 protected:
237 sal_uInt64 m_nStrPos;
238 sal_uInt64 m_nOwnPos; // Position after # and Len
239 sal_uInt16 nGrbit;
240 SCTAB nTab;
242 ExcBundlesheetBase();
244 public:
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
255 private:
256 OString aName;
258 virtual void SaveCont( XclExpStream& rStrm ) override;
260 public:
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
270 private:
271 static const sal_uInt8 pMyData[];
272 static const std::size_t nMyLen;
273 public:
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
281 public:
282 explicit XclExpCountry( const XclExpRoot& rRoot );
284 private:
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
296 public:
297 explicit XclExpWsbool( bool bFitToPages );
301 * Save sheetPr element and its children for xlsx export.
303 class XclExpXmlSheetPr : public XclExpRecordBase
305 public:
306 explicit XclExpXmlSheetPr(
307 bool bFitToPages, SCTAB nScTab, const Color& rTabColor, bool bSummaryBelow, XclExpFilterManager* pManager );
309 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
311 private:
312 SCTAB mnScTab;
313 XclExpFilterManager* mpManager;
314 bool mbFitToPage;
315 Color maTabColor;
316 bool mbSummaryBelow;
319 class XclExpFiltermode : public XclExpEmptyRecord
321 public:
322 explicit XclExpFiltermode();
325 class XclExpAutofilterinfo : public XclExpUInt16Record
327 public:
328 explicit XclExpAutofilterinfo( const ScAddress& rStartPos, SCCOL nScCol );
330 const ScAddress& GetStartPos() const { return maStartPos; }
331 SCCOL GetColCount() const { return static_cast< SCCOL >( GetValue() ); }
333 private:
334 ScAddress maStartPos;
337 class ExcFilterCondition
339 private:
340 sal_uInt8 nType;
341 sal_uInt8 nOper;
342 std::unique_ptr<XclExpString>
343 pText;
345 protected:
346 public:
347 ExcFilterCondition();
348 ~ExcFilterCondition();
350 bool IsEmpty() const { return (nType == EXC_AFTYPE_NOTUSED); }
351 std::size_t GetTextBytes() const;
353 void SetCondition( sal_uInt8 nTp, sal_uInt8 nOp, const OUString* pT );
355 void Save( XclExpStream& rStrm );
356 void SaveXml( XclExpXmlStream& rStrm );
357 void SaveText( XclExpStream& rStrm );
360 class XclExpAutofilter : public XclExpRecord, protected XclExpRoot
362 private:
363 enum FilterType
365 Empty,
366 FilterCondition,
367 MultiValue,
368 BlankValue,
369 ColorValue
371 FilterType meType;
372 sal_uInt16 nCol;
373 bool bIsButtonHidden;
374 sal_uInt16 nFlags;
375 bool bHasBlankValue;
376 ExcFilterCondition aCond[ 2 ];
377 std::vector<std::pair<OUString, bool>> maMultiValues; // first->values, second->bDateFormat
378 std::vector<std::pair<::Color, bool>> maColorValues; // first->Color, second->bIsBackgroundColor (vs. TextColor)
380 bool AddCondition( ScQueryConnect eConn, sal_uInt8 nType,
381 sal_uInt8 nOp, const OUString* pText, bool bSimple = false );
383 virtual void WriteBody( XclExpStream& rStrm ) override;
385 public:
386 XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC, bool bIsEmpty = false );
388 sal_uInt16 GetCol() const { return nCol; }
389 bool HasTop10() const { return ::get_flag( nFlags, EXC_AFFLAG_TOP10 ); }
391 bool HasCondition() const;
392 bool AddEntry( const ScQueryEntry& rEntry );
393 void AddMultiValueEntry( const ScQueryEntry& rEntry );
394 void SetButtonHidden(bool bValue) { bIsButtonHidden = bValue; }
395 void AddColorEntry( const ScQueryEntry& rEntry );
397 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
400 class ExcAutoFilterRecs : public XclExpRecordBase, protected XclExpRoot
402 public:
403 /** @param pDefinedData
404 If nullptr, obtain anonymous ScDBData from sheet nTab.
405 Else, use defined database range; used with XclExpTables.
407 explicit ExcAutoFilterRecs( const XclExpRoot& rRoot, SCTAB nTab, const ScDBData* pDefinedData );
408 virtual ~ExcAutoFilterRecs() override;
410 void AddObjRecs();
412 virtual void Save( XclExpStream& rStrm ) override;
413 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
415 bool HasFilterMode() const;
417 private:
418 XclExpAutofilter* GetByCol( SCCOL nCol ); // always 0-based
419 bool IsFiltered( SCCOL nCol );
421 private:
422 typedef XclExpRecordList< XclExpAutofilter > XclExpAutofilterList;
423 typedef XclExpAutofilterList::RecordRefType XclExpAutofilterRef;
425 XclExpAutofilterList maFilterList;
426 rtl::Reference<XclExpFiltermode> m_pFilterMode;
427 rtl::Reference<XclExpAutofilterinfo> m_pFilterInfo;
428 ScRange maRef;
429 bool mbAutoFilter;
431 ScRange maSortRef; // sort area without headers
432 std::vector< std::tuple<ScRange, OUString, bool> > maSortCustomList; // sorted column with list of sorted items
435 /** Sheet filter manager. Contains auto filters or advanced filters from all sheets. */
436 class XclExpFilterManager : protected XclExpRoot
438 public:
439 explicit XclExpFilterManager( const XclExpRoot& rRoot );
441 /** Creates the filter records for the specified sheet.
442 @descr Creates and inserts related built-in NAME records. Therefore this
443 function is called from the name buffer itself. */
444 void InitTabFilter( SCTAB nScTab );
446 /** Returns a record object containing all filter records for the specified sheet. */
447 XclExpRecordRef CreateRecord( SCTAB nScTab );
449 /** Returns whether or not FilterMode is present */
450 bool HasFilterMode( SCTAB nScTab );
452 private:
453 using XclExpRoot::CreateRecord;
455 typedef rtl::Reference< ExcAutoFilterRecs > XclExpTabFilterRef;
456 typedef ::std::map< SCTAB, XclExpTabFilterRef > XclExpTabFilterMap;
458 XclExpTabFilterMap maFilterMap;
461 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */