Line data Source code
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 : #ifndef SC_XMLSTYLESEXPORTHELPER_HXX
21 : #define SC_XMLSTYLESEXPORTHELPER_HXX
22 :
23 : #include <vector>
24 : #include <list>
25 : #include <com/sun/star/uno/Any.h>
26 : #include <com/sun/star/table/CellRangeAddress.hpp>
27 : #include <com/sun/star/table/CellAddress.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 <boost/ptr_container/ptr_vector.hpp>
33 : #include <mdds/flat_segment_tree.hpp>
34 :
35 : class ScDocument;
36 : class ScXMLExport;
37 :
38 0 : struct ScMyValidation
39 : {
40 : OUString sName;
41 : OUString sErrorMessage;
42 : OUString sErrorTitle;
43 : OUString sImputMessage;
44 : OUString sImputTitle;
45 : OUString sFormula1;
46 : OUString sFormula2;
47 : com::sun::star::table::CellAddress aBaseCell;
48 : com::sun::star::sheet::ValidationAlertStyle aAlertStyle;
49 : com::sun::star::sheet::ValidationType aValidationType;
50 : com::sun::star::sheet::ConditionOperator aOperator;
51 : sal_Int16 nShowList;
52 : bool bShowErrorMessage;
53 : bool bShowImputMessage;
54 : bool bIgnoreBlanks;
55 :
56 : ScMyValidation();
57 : ~ScMyValidation();
58 :
59 : bool IsEqual(const ScMyValidation& aVal) const;
60 : };
61 :
62 : typedef std::vector<ScMyValidation> ScMyValidationVec;
63 :
64 : class ScMyValidationsContainer
65 : {
66 : private:
67 : ScMyValidationVec aValidationVec;
68 : const OUString sEmptyString;
69 : const OUString sERRALSTY;
70 : const OUString sIGNOREBL;
71 : const OUString sSHOWLIST;
72 : const OUString sTYPE;
73 : const OUString sSHOWINP;
74 : const OUString sSHOWERR;
75 : const OUString sINPTITLE;
76 : const OUString sINPMESS;
77 : const OUString sERRTITLE;
78 : const OUString sERRMESS;
79 : const OUString sOnError;
80 : const OUString sEventType;
81 : const OUString sStarBasic;
82 : const OUString sScript;
83 : const OUString sLibrary;
84 : const OUString sMacroName;
85 :
86 : public:
87 : ScMyValidationsContainer();
88 : ~ScMyValidationsContainer();
89 : bool AddValidation(const com::sun::star::uno::Any& aAny,
90 : sal_Int32& nValidationIndex);
91 : OUString GetCondition(ScXMLExport& rExport, const ScMyValidation& aValidation);
92 : OUString GetBaseCellAddress(ScDocument* pDoc, const com::sun::star::table::CellAddress& aCell);
93 : void WriteMessage(ScXMLExport& rExport,
94 : const OUString& sTitle, const OUString& sMessage,
95 : const bool bShowMessage, const bool bIsHelpMessage);
96 : void WriteValidations(ScXMLExport& rExport);
97 : const OUString& GetValidationName(const sal_Int32 nIndex);
98 : };
99 :
100 : //==============================================================================
101 :
102 : struct ScMyDefaultStyle
103 : {
104 : sal_Int32 nIndex;
105 : sal_Int32 nRepeat;
106 : bool bIsAutoStyle;
107 :
108 3147825 : ScMyDefaultStyle() : nIndex(-1), nRepeat(1),
109 3147825 : bIsAutoStyle(true) {}
110 : };
111 :
112 : typedef std::vector<ScMyDefaultStyle> ScMyDefaultStyleList;
113 :
114 : class ScFormatRangeStyles;
115 :
116 20 : class ScMyDefaultStyles
117 : {
118 : ScMyDefaultStyleList maRowDefaults;
119 : ScMyDefaultStyleList maColDefaults;
120 :
121 : sal_Int32 GetStyleNameIndex(const ScFormatRangeStyles* pCellStyles,
122 : const sal_Int32 nTable, const sal_Int32 nPos,
123 : const sal_Int32 i, const bool bRow, bool& bIsAutoStyle);
124 : void FillDefaultStyles(const sal_Int32 nTable,
125 : const sal_Int32 nLastRow, const sal_Int32 nLastCol,
126 : const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc,
127 : const bool bRow);
128 : public:
129 :
130 : void FillDefaultStyles(const sal_Int32 nTable,
131 : const sal_Int32 nLastRow, const sal_Int32 nLastCol,
132 : const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc);
133 :
134 67 : const ScMyDefaultStyleList* GetRowDefaults() const { return &maRowDefaults; }
135 4190 : const ScMyDefaultStyleList* GetColDefaults() const { return &maColDefaults; }
136 : };
137 :
138 : struct ScMyRowFormatRange
139 : {
140 : sal_Int32 nStartColumn;
141 : sal_Int32 nRepeatColumns;
142 : sal_Int32 nRepeatRows;
143 : sal_Int32 nIndex;
144 : sal_Int32 nValidationIndex;
145 : bool bIsAutoStyle;
146 :
147 : ScMyRowFormatRange();
148 : bool operator<(const ScMyRowFormatRange& rRange) const;
149 : };
150 :
151 : class ScRowFormatRanges
152 : {
153 : typedef std::list<ScMyRowFormatRange> ScMyRowFormatRangesList;
154 : ScMyRowFormatRangesList aRowFormatRanges;
155 : const ScMyDefaultStyleList* pRowDefaults;
156 : const ScMyDefaultStyleList* pColDefaults;
157 : sal_uInt32 nSize;
158 :
159 : void AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
160 : const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange);
161 :
162 : public:
163 : ScRowFormatRanges();
164 : ScRowFormatRanges(const ScRowFormatRanges* pRanges);
165 : ~ScRowFormatRanges();
166 :
167 9 : void SetRowDefaults(const ScMyDefaultStyleList* pDefaults) { pRowDefaults = pDefaults; }
168 9 : void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
169 : void Clear();
170 : void AddRange(ScMyRowFormatRange& rFormatRange, const sal_Int32 nStartRow);
171 : bool GetNext(ScMyRowFormatRange& rFormatRange);
172 : sal_Int32 GetMaxRows() const;
173 : sal_Int32 GetSize() const;
174 : void Sort();
175 : };
176 :
177 : typedef std::vector<OUString*> ScMyOUStringVec;
178 :
179 : struct ScMyFormatRange
180 : {
181 : com::sun::star::table::CellRangeAddress aRangeAddress;
182 : sal_Int32 nStyleNameIndex;
183 : sal_Int32 nValidationIndex;
184 : sal_Int32 nNumberFormat;
185 : bool bIsAutoStyle;
186 :
187 : ScMyFormatRange();
188 : bool operator< (const ScMyFormatRange& rRange) const;
189 : };
190 :
191 : class ScFormatRangeStyles
192 : {
193 : typedef std::list<ScMyFormatRange> ScMyFormatRangeAddresses;
194 : typedef std::vector<ScMyFormatRangeAddresses*> ScMyFormatRangeListVec;
195 :
196 : ScMyFormatRangeListVec aTables;
197 : ScMyOUStringVec aStyleNames;
198 : ScMyOUStringVec aAutoStyleNames;
199 : const ScMyDefaultStyleList* pRowDefaults;
200 : const ScMyDefaultStyleList* pColDefaults;
201 :
202 : public:
203 : ScFormatRangeStyles();
204 : ~ScFormatRangeStyles();
205 :
206 9 : void SetRowDefaults(const ScMyDefaultStyleList* pDefaults) { pRowDefaults = pDefaults; }
207 9 : void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
208 : void AddNewTable(const sal_Int32 nTable);
209 : bool AddStyleName(OUString* pString, sal_Int32& rIndex, const bool bIsAutoStyle = true);
210 : sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix, bool& bIsAutoStyle);
211 : // does not delete ranges
212 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
213 : bool& bIsAutoStyle) const;
214 : // deletes not necessary ranges if wanted
215 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
216 : bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow);
217 : void GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
218 : const sal_Int32 nTable, ScRowFormatRanges* pFormatRanges);
219 : void AddRangeStyleName(const com::sun::star::table::CellRangeAddress aCellRangeAddress, const sal_Int32 nStringIndex,
220 : const bool bIsAutoStyle, const sal_Int32 nValidationIndex, const sal_Int32 nNumberFormat);
221 : OUString* GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle);
222 : void Sort();
223 : };
224 :
225 : class ScColumnRowStylesBase
226 : {
227 : ScMyOUStringVec aStyleNames;
228 :
229 : public:
230 : ScColumnRowStylesBase();
231 : virtual ~ScColumnRowStylesBase();
232 :
233 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) = 0;
234 : sal_Int32 AddStyleName(OUString* pString);
235 : sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix);
236 : virtual OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField) = 0;
237 : OUString* GetStyleNameByIndex(const sal_Int32 nIndex);
238 : };
239 :
240 : struct ScColumnStyle
241 : {
242 : sal_Int32 nIndex;
243 : bool bIsVisible;
244 :
245 9247 : ScColumnStyle() : nIndex(-1), bIsVisible(true) {}
246 : };
247 :
248 : class ScColumnStyles : public ScColumnRowStylesBase
249 : {
250 : typedef std::vector<ScColumnStyle> ScMyColumnStyleVec;
251 : typedef std::vector<ScMyColumnStyleVec> ScMyColumnVectorVec;
252 : ScMyColumnVectorVec aTables;
253 :
254 : public:
255 : ScColumnStyles();
256 : ~ScColumnStyles();
257 :
258 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields);
259 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
260 : bool& bIsVisible);
261 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex, const bool bIsVisible);
262 : virtual OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField);
263 : };
264 :
265 : class ScRowStyles : public ScColumnRowStylesBase
266 : {
267 : typedef ::mdds::flat_segment_tree<sal_Int32, sal_Int32> StylesType;
268 : ::boost::ptr_vector<StylesType> aTables;
269 : struct Cache
270 : {
271 : sal_Int32 mnTable;
272 : sal_Int32 mnStart;
273 : sal_Int32 mnEnd;
274 : sal_Int32 mnStyle;
275 : Cache();
276 :
277 : bool hasCache(sal_Int32 nTable, sal_Int32 nField) const;
278 : };
279 : Cache maCache;
280 :
281 : public:
282 : ScRowStyles();
283 : ~ScRowStyles();
284 :
285 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields);
286 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField);
287 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex);
288 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField, const sal_Int32 nStringIndex, const sal_Int32 nEndField);
289 : virtual OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField);
290 : };
291 :
292 : #endif
293 :
294 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|