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 : struct ScMyDefaultStyle
101 : {
102 : sal_Int32 nIndex;
103 : sal_Int32 nRepeat;
104 : bool bIsAutoStyle;
105 :
106 2129 : ScMyDefaultStyle() : nIndex(-1), nRepeat(1),
107 2129 : bIsAutoStyle(true) {}
108 : };
109 :
110 : typedef std::vector<ScMyDefaultStyle> ScMyDefaultStyleList;
111 :
112 : class ScFormatRangeStyles;
113 :
114 40 : class ScMyDefaultStyles
115 : {
116 : ScMyDefaultStyleList maColDefaults;
117 :
118 : sal_Int32 GetStyleNameIndex(const ScFormatRangeStyles* pCellStyles,
119 : const sal_Int32 nTable, const sal_Int32 nPos,
120 : const sal_Int32 i, bool& bIsAutoStyle);
121 : public:
122 :
123 : void FillDefaultStyles(const sal_Int32 nTable,
124 : const sal_Int32 nLastRow, const sal_Int32 nLastCol,
125 : const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc);
126 :
127 4317 : const ScMyDefaultStyleList* GetColDefaults() const { return &maColDefaults; }
128 : };
129 :
130 : struct ScMyRowFormatRange
131 : {
132 : sal_Int32 nStartColumn;
133 : sal_Int32 nRepeatColumns;
134 : sal_Int32 nRepeatRows;
135 : sal_Int32 nIndex;
136 : sal_Int32 nValidationIndex;
137 : bool bIsAutoStyle;
138 :
139 : ScMyRowFormatRange();
140 : bool operator<(const ScMyRowFormatRange& rRange) const;
141 : };
142 :
143 : class ScRowFormatRanges
144 : {
145 : typedef std::list<ScMyRowFormatRange> ScMyRowFormatRangesList;
146 : ScMyRowFormatRangesList aRowFormatRanges;
147 : const ScMyDefaultStyleList* pColDefaults;
148 : sal_uInt32 nSize;
149 :
150 : void AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
151 : const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange);
152 :
153 : public:
154 : ScRowFormatRanges();
155 : ScRowFormatRanges(const ScRowFormatRanges* pRanges);
156 : ~ScRowFormatRanges();
157 :
158 22 : void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
159 : void Clear();
160 : void AddRange(ScMyRowFormatRange& rFormatRange);
161 : bool GetNext(ScMyRowFormatRange& rFormatRange);
162 : sal_Int32 GetMaxRows() const;
163 : sal_Int32 GetSize() const;
164 : void Sort();
165 : };
166 :
167 : typedef std::vector<OUString*> ScMyOUStringVec;
168 :
169 : struct ScMyFormatRange
170 : {
171 : com::sun::star::table::CellRangeAddress aRangeAddress;
172 : sal_Int32 nStyleNameIndex;
173 : sal_Int32 nValidationIndex;
174 : sal_Int32 nNumberFormat;
175 : bool bIsAutoStyle;
176 :
177 : ScMyFormatRange();
178 : bool operator< (const ScMyFormatRange& rRange) const;
179 : };
180 :
181 : class ScFormatRangeStyles
182 : {
183 : typedef std::list<ScMyFormatRange> ScMyFormatRangeAddresses;
184 : typedef std::vector<ScMyFormatRangeAddresses*> ScMyFormatRangeListVec;
185 :
186 : ScMyFormatRangeListVec aTables;
187 : ScMyOUStringVec aStyleNames;
188 : ScMyOUStringVec aAutoStyleNames;
189 : const ScMyDefaultStyleList* pColDefaults;
190 :
191 : public:
192 : ScFormatRangeStyles();
193 : ~ScFormatRangeStyles();
194 :
195 22 : void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
196 : void AddNewTable(const sal_Int32 nTable);
197 : bool AddStyleName(OUString* pString, sal_Int32& rIndex, const bool bIsAutoStyle = true);
198 : sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix, bool& bIsAutoStyle);
199 : // does not delete ranges
200 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
201 : bool& bIsAutoStyle) const;
202 : // deletes not necessary ranges if wanted
203 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
204 : bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow);
205 : void GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
206 : const sal_Int32 nTable, ScRowFormatRanges* pFormatRanges);
207 : void AddRangeStyleName(const com::sun::star::table::CellRangeAddress aCellRangeAddress, const sal_Int32 nStringIndex,
208 : const bool bIsAutoStyle, const sal_Int32 nValidationIndex, const sal_Int32 nNumberFormat);
209 : OUString* GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle);
210 : void Sort();
211 : };
212 :
213 : class ScColumnRowStylesBase
214 : {
215 : ScMyOUStringVec aStyleNames;
216 :
217 : public:
218 : ScColumnRowStylesBase();
219 : virtual ~ScColumnRowStylesBase();
220 :
221 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) = 0;
222 : sal_Int32 AddStyleName(OUString* pString);
223 : sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix);
224 : virtual OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField) = 0;
225 : OUString* GetStyleNameByIndex(const sal_Int32 nIndex);
226 : };
227 :
228 : struct ScColumnStyle
229 : {
230 : sal_Int32 nIndex;
231 : bool bIsVisible;
232 :
233 22588 : ScColumnStyle() : nIndex(-1), bIsVisible(true) {}
234 : };
235 :
236 : class ScColumnStyles : public ScColumnRowStylesBase
237 : {
238 : typedef std::vector<ScColumnStyle> ScMyColumnStyleVec;
239 : typedef std::vector<ScMyColumnStyleVec> ScMyColumnVectorVec;
240 : ScMyColumnVectorVec aTables;
241 :
242 : public:
243 : ScColumnStyles();
244 : virtual ~ScColumnStyles();
245 :
246 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) SAL_OVERRIDE;
247 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
248 : bool& bIsVisible);
249 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex, const bool bIsVisible);
250 : virtual OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField) SAL_OVERRIDE;
251 : };
252 :
253 : class ScRowStyles : public ScColumnRowStylesBase
254 : {
255 : typedef ::mdds::flat_segment_tree<sal_Int32, sal_Int32> StylesType;
256 : ::boost::ptr_vector<StylesType> aTables;
257 : struct Cache
258 : {
259 : sal_Int32 mnTable;
260 : sal_Int32 mnStart;
261 : sal_Int32 mnEnd;
262 : sal_Int32 mnStyle;
263 : Cache();
264 :
265 : bool hasCache(sal_Int32 nTable, sal_Int32 nField) const;
266 : };
267 : Cache maCache;
268 :
269 : public:
270 : ScRowStyles();
271 : virtual ~ScRowStyles();
272 :
273 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) SAL_OVERRIDE;
274 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField);
275 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex);
276 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField, const sal_Int32 nStringIndex, const sal_Int32 nEndField);
277 : virtual OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField) SAL_OVERRIDE;
278 : };
279 :
280 : #endif
281 :
282 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|