LibreOffice Module sc (master)  1
XMLStylesExportHelper.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #include <vector>
23 #include <memory>
24 #include <list>
25 
26 #include <address.hxx>
27 #include <com/sun/star/table/CellRangeAddress.hpp>
28 #include <com/sun/star/sheet/ConditionOperator.hpp>
29 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
30 #include <com/sun/star/sheet/ValidationType.hpp>
31 
32 #include <mdds/flat_segment_tree.hpp>
33 
34 class ScDocument;
35 class ScXMLExport;
36 
38 {
39  OUString sName;
40  OUString sErrorMessage;
41  OUString sErrorTitle;
42  OUString sInputMessage;
43  OUString sInputTitle;
44  OUString sFormula1;
45  OUString sFormula2;
47  css::sheet::ValidationAlertStyle aAlertStyle;
48  css::sheet::ValidationType aValidationType;
49  css::sheet::ConditionOperator aOperator;
50  sal_Int16 nShowList;
54 
56 
57  bool IsEqual(const ScMyValidation& aVal) const;
58 };
59 
61 {
62 private:
63  std::vector<ScMyValidation> aValidationVec;
64 public:
67  void AddValidation(const css::uno::Any& aAny,
68  sal_Int32& nValidationIndex);
69  static OUString GetCondition(ScXMLExport& rExport, const ScMyValidation& aValidation);
70  static OUString GetBaseCellAddress(const ScDocument* pDoc, const ScAddress& aCell);
71  static void WriteMessage(ScXMLExport& rExport,
72  const OUString& sTitle, const OUString& sMessage,
73  const bool bShowMessage, const bool bIsHelpMessage);
74  void WriteValidations(ScXMLExport& rExport);
75  const OUString& GetValidationName(const sal_Int32 nIndex);
76 };
77 
79 {
80  sal_Int32 nIndex;
81  sal_Int32 nRepeat;
83 
84  ScMyDefaultStyle() : nIndex(-1), nRepeat(1),
85  bIsAutoStyle(true) {}
86 };
87 
88 typedef std::vector<ScMyDefaultStyle> ScMyDefaultStyleList;
89 
91 
93 {
95 
96  static sal_Int32 GetStyleNameIndex(const ScFormatRangeStyles* pCellStyles,
97  const sal_Int32 nTable, const sal_Int32 nPos,
98  const sal_Int32 i, bool& bIsAutoStyle);
99 public:
100 
101  void FillDefaultStyles(const sal_Int32 nTable,
102  const sal_Int32 nLastRow, const sal_Int32 nLastCol,
103  const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc);
104 
106 };
107 
109 {
110  sal_Int32 nStartColumn;
111  sal_Int32 nRepeatColumns;
112  sal_Int32 nRepeatRows;
113  sal_Int32 nIndex;
114  sal_Int32 nValidationIndex;
116 
118  bool operator<(const ScMyRowFormatRange& rRange) const;
119 };
120 
122 {
123  typedef std::list<ScMyRowFormatRange> ScMyRowFormatRangesList;
124  ScMyRowFormatRangesList aRowFormatRanges;
126  sal_uInt32 nSize;
127 
128  void AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
129  const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange);
130 
131 public:
133  explicit ScRowFormatRanges(const ScRowFormatRanges* pRanges);
135 
136  void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
137  void Clear();
138  void AddRange(const ScMyRowFormatRange& rFormatRange);
139  bool GetNext(ScMyRowFormatRange& rFormatRange);
140  sal_Int32 GetMaxRows() const;
141  sal_Int32 GetSize() const { return nSize;}
142  void Sort();
143 };
144 
145 
147 {
148  css::table::CellRangeAddress aRangeAddress;
149  sal_Int32 nStyleNameIndex;
150  sal_Int32 nValidationIndex;
151  sal_Int32 nNumberFormat;
153 
154  ScMyFormatRange();
155  bool operator< (const ScMyFormatRange& rRange) const;
156 };
157 
159 {
160  typedef std::list<ScMyFormatRange> ScMyFormatRangeAddresses;
161  typedef std::vector<ScMyFormatRangeAddresses> ScMyFormatRangeListVec;
162 
163  ScMyFormatRangeListVec aTables;
164  std::vector<OUString> aStyleNames;
165  std::vector<OUString> aAutoStyleNames;
167 
168 public:
171 
172  void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
173  void AddNewTable(const sal_Int32 nTable);
174  bool AddStyleName(const OUString& rString, sal_Int32& rIndex, const bool bIsAutoStyle = true);
175  sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix, bool& bIsAutoStyle);
176  // does not delete ranges
177  sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
178  bool& bIsAutoStyle) const;
179  // deletes not necessary ranges if wanted
180  sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
181  bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow);
182  void GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
183  const sal_Int32 nTable, ScRowFormatRanges* pFormatRanges);
184  void AddRangeStyleName(const css::table::CellRangeAddress& rCellRangeAddress, const sal_Int32 nStringIndex,
185  const bool bIsAutoStyle, const sal_Int32 nValidationIndex, const sal_Int32 nNumberFormat);
186  OUString& GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle);
187  void Sort();
188 };
189 
191 {
192  std::vector<OUString> aStyleNames;
193 
194 public:
196  virtual ~ScColumnRowStylesBase();
197 
198  virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) = 0;
199  sal_Int32 AddStyleName(const OUString & rString);
200  sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix);
201  OUString& GetStyleNameByIndex(const sal_Int32 nIndex);
202 };
203 
205 {
206  sal_Int32 nIndex;
208 
209  ScColumnStyle() : nIndex(-1), bIsVisible(true) {}
210 };
211 
213 {
214  typedef std::vector<ScColumnStyle> ScMyColumnStyleVec;
215  typedef std::vector<ScMyColumnStyleVec> ScMyColumnVectorVec;
216  ScMyColumnVectorVec aTables;
217 
218 public:
219  ScColumnStyles();
220  virtual ~ScColumnStyles() override;
221 
222  virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) override;
223  sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
224  bool& bIsVisible);
225  void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex, const bool bIsVisible);
226 };
227 
229 {
230  typedef ::mdds::flat_segment_tree<sal_Int32, sal_Int32> StylesType;
231  std::vector<std::unique_ptr<StylesType> > aTables;
232  struct Cache
233  {
234  sal_Int32 mnTable;
235  sal_Int32 mnStart;
236  sal_Int32 mnEnd;
237  sal_Int32 mnStyle;
238  Cache();
239 
240  bool hasCache(sal_Int32 nTable, sal_Int32 nField) const;
241  };
243 
244 public:
245  ScRowStyles();
246  virtual ~ScRowStyles() override;
247 
248  virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) override;
249  sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField);
250  void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex);
251  void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField, const sal_Int32 nStringIndex, const sal_Int32 nEndField);
252 };
253 
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator<(const ScMyFormatRange &rRange) const
sal_Int32 GetIndexOfStyleName(const OUString &rString, const OUString &rPrefix)
void AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex, const bool bPrevAutoStyle, const ScMyRowFormatRange &rFormatRange)
bool operator<(const ScMyRowFormatRange &rRange) const
static OUString GetBaseCellAddress(const ScDocument *pDoc, const ScAddress &aCell)
void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex, const bool bIsVisible)
static void WriteMessage(ScXMLExport &rExport, const OUString &sTitle, const OUString &sMessage, const bool bShowMessage, const bool bIsHelpMessage)
virtual ~ScColumnStyles() override
void AddRangeStyleName(const css::table::CellRangeAddress &rCellRangeAddress, const sal_Int32 nStringIndex, const bool bIsAutoStyle, const sal_Int32 nValidationIndex, const sal_Int32 nNumberFormat)
void SetColDefaults(const ScMyDefaultStyleList *pDefaults)
sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField, bool &bIsVisible)
css::sheet::ConditionOperator aOperator
css::sheet::ValidationAlertStyle aAlertStyle
OUString & GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle)
const ScMyDefaultStyleList * pColDefaults
void SetColDefaults(const ScMyDefaultStyleList *pDefaults)
ScMyFormatRangeListVec aTables
std::vector< ScMyFormatRangeAddresses > ScMyFormatRangeListVec
sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow, bool &bIsAutoStyle) const
void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex)
std::list< ScMyFormatRange > ScMyFormatRangeAddresses
void AddValidation(const css::uno::Any &aAny, sal_Int32 &nValidationIndex)
sal_Int32 AddStyleName(const OUString &rString)
bool hasCache(sal_Int32 nTable, sal_Int32 nField) const
std::vector< ScColumnStyle > ScMyColumnStyleVec
::mdds::flat_segment_tree< sal_Int32, sal_Int32 > StylesType
ScMyDefaultStyleList maColDefaults
css::sheet::ValidationType aValidationType
css::table::CellRangeAddress aRangeAddress
sal_Int32 GetSize() const
virtual ~ScRowStyles() override
std::list< ScMyRowFormatRange > ScMyRowFormatRangesList
void WriteValidations(ScXMLExport &rExport)
std::vector< OUString > aStyleNames
sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
static OUString GetCondition(ScXMLExport &rExport, const ScMyValidation &aValidation)
virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) override
void FillDefaultStyles(const sal_Int32 nTable, const sal_Int32 nLastRow, const sal_Int32 nLastCol, const ScFormatRangeStyles *pCellStyles, ScDocument *pDoc)
static sal_Int32 GetStyleNameIndex(const ScFormatRangeStyles *pCellStyles, const sal_Int32 nTable, const sal_Int32 nPos, const sal_Int32 i, bool &bIsAutoStyle)
virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)=0
std::vector< ScMyColumnStyleVec > ScMyColumnVectorVec
const OUString & GetValidationName(const sal_Int32 nIndex)
std::vector< OUString > aAutoStyleNames
std::vector< ScMyValidation > aValidationVec
std::vector< OUString > aStyleNames
bool GetNext(ScMyRowFormatRange &rFormatRange)
bool AddStyleName(const OUString &rString, sal_Int32 &rIndex, const bool bIsAutoStyle=true)
const ScMyDefaultStyleList & GetColDefaults() const
virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) override
ScMyRowFormatRangesList aRowFormatRanges
OUString & GetStyleNameByIndex(const sal_Int32 nIndex)
void AddNewTable(const sal_Int32 nTable)
sal_Int32 GetMaxRows() const
std::vector< std::unique_ptr< StylesType > > aTables
bool IsEqual(const ScMyValidation &aVal) const
std::vector< ScMyDefaultStyle > ScMyDefaultStyleList
ScMyColumnVectorVec aTables
const ScMyDefaultStyleList * pColDefaults
void GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow, const sal_Int32 nTable, ScRowFormatRanges *pFormatRanges)
sal_Int32 GetIndexOfStyleName(const OUString &rString, const OUString &rPrefix, bool &bIsAutoStyle)