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 : rtl::OUString sName;
41 : rtl::OUString sErrorMessage;
42 : rtl::OUString sErrorTitle;
43 : rtl::OUString sImputMessage;
44 : rtl::OUString sImputTitle;
45 : rtl::OUString sFormula1;
46 : rtl::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 rtl::OUString sEmptyString;
69 : const rtl::OUString sERRALSTY;
70 : const rtl::OUString sIGNOREBL;
71 : const rtl::OUString sSHOWLIST;
72 : const rtl::OUString sTYPE;
73 : const rtl::OUString sSHOWINP;
74 : const rtl::OUString sSHOWERR;
75 : const rtl::OUString sINPTITLE;
76 : const rtl::OUString sINPMESS;
77 : const rtl::OUString sERRTITLE;
78 : const rtl::OUString sERRMESS;
79 : const rtl::OUString sOnError;
80 : const rtl::OUString sEventType;
81 : const rtl::OUString sStarBasic;
82 : const rtl::OUString sScript;
83 : const rtl::OUString sLibrary;
84 : const rtl::OUString sMacroName;
85 :
86 : public:
87 : ScMyValidationsContainer();
88 : ~ScMyValidationsContainer();
89 : bool AddValidation(const com::sun::star::uno::Any& aAny,
90 : sal_Int32& nValidationIndex);
91 : rtl::OUString GetCondition(ScXMLExport& rExport, const ScMyValidation& aValidation);
92 : rtl::OUString GetBaseCellAddress(ScDocument* pDoc, const com::sun::star::table::CellAddress& aCell);
93 : void WriteMessage(ScXMLExport& rExport,
94 : const rtl::OUString& sTitle, const rtl::OUString& sMessage,
95 : const bool bShowMessage, const bool bIsHelpMessage);
96 : void WriteValidations(ScXMLExport& rExport);
97 : const rtl::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 4 : ScMyDefaultStyle() : nIndex(-1), nRepeat(1),
109 4 : bIsAutoStyle(true) {}
110 : };
111 :
112 : typedef std::vector<ScMyDefaultStyle> ScMyDefaultStyleList;
113 :
114 : class ScFormatRangeStyles;
115 :
116 : class ScMyDefaultStyles
117 : {
118 : ScMyDefaultStyleList* pRowDefaults;
119 : ScMyDefaultStyleList* pColDefaults;
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 2 : ScMyDefaultStyles() : pRowDefaults(NULL), pColDefaults(NULL) {}
130 : ~ScMyDefaultStyles();
131 :
132 : void FillDefaultStyles(const sal_Int32 nTable,
133 : const sal_Int32 nLastRow, const sal_Int32 nLastCol,
134 : const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc);
135 :
136 6 : const ScMyDefaultStyleList* GetRowDefaults() const { return pRowDefaults; }
137 8 : const ScMyDefaultStyleList* GetColDefaults() const { return pColDefaults; }
138 : };
139 :
140 : struct ScMyRowFormatRange
141 : {
142 : sal_Int32 nStartColumn;
143 : sal_Int32 nRepeatColumns;
144 : sal_Int32 nRepeatRows;
145 : sal_Int32 nIndex;
146 : sal_Int32 nValidationIndex;
147 : bool bIsAutoStyle;
148 :
149 : ScMyRowFormatRange();
150 : bool operator<(const ScMyRowFormatRange& rRange) const;
151 : };
152 :
153 : class ScRowFormatRanges
154 : {
155 : typedef std::list<ScMyRowFormatRange> ScMyRowFormatRangesList;
156 : ScMyRowFormatRangesList aRowFormatRanges;
157 : const ScMyDefaultStyleList* pRowDefaults;
158 : const ScMyDefaultStyleList* pColDefaults;
159 : sal_uInt32 nSize;
160 :
161 : void AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
162 : const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange);
163 :
164 : public:
165 : ScRowFormatRanges();
166 : ScRowFormatRanges(const ScRowFormatRanges* pRanges);
167 : ~ScRowFormatRanges();
168 :
169 2 : void SetRowDefaults(const ScMyDefaultStyleList* pDefaults) { pRowDefaults = pDefaults; }
170 2 : void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
171 : void Clear();
172 : void AddRange(ScMyRowFormatRange& rFormatRange, const sal_Int32 nStartRow);
173 : bool GetNext(ScMyRowFormatRange& rFormatRange);
174 : sal_Int32 GetMaxRows() const;
175 : sal_Int32 GetSize() const;
176 : void Sort();
177 : };
178 :
179 : typedef std::vector<rtl::OUString*> ScMyOUStringVec;
180 :
181 : struct ScMyFormatRange
182 : {
183 : com::sun::star::table::CellRangeAddress aRangeAddress;
184 : sal_Int32 nStyleNameIndex;
185 : sal_Int32 nValidationIndex;
186 : sal_Int32 nNumberFormat;
187 : bool bIsAutoStyle;
188 :
189 : ScMyFormatRange();
190 : bool operator< (const ScMyFormatRange& rRange) const;
191 : };
192 :
193 : class ScFormatRangeStyles
194 : {
195 : typedef std::list<ScMyFormatRange> ScMyFormatRangeAddresses;
196 : typedef std::vector<ScMyFormatRangeAddresses*> ScMyFormatRangeListVec;
197 :
198 : ScMyFormatRangeListVec aTables;
199 : ScMyOUStringVec aStyleNames;
200 : ScMyOUStringVec aAutoStyleNames;
201 : const ScMyDefaultStyleList* pRowDefaults;
202 : const ScMyDefaultStyleList* pColDefaults;
203 :
204 : public:
205 : ScFormatRangeStyles();
206 : ~ScFormatRangeStyles();
207 :
208 2 : void SetRowDefaults(const ScMyDefaultStyleList* pDefaults) { pRowDefaults = pDefaults; }
209 2 : void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
210 : void AddNewTable(const sal_Int32 nTable);
211 : bool AddStyleName(rtl::OUString* pString, sal_Int32& rIndex, const bool bIsAutoStyle = true);
212 : sal_Int32 GetIndexOfStyleName(const rtl::OUString& rString, const rtl::OUString& rPrefix, bool& bIsAutoStyle);
213 : // does not delete ranges
214 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
215 : bool& bIsAutoStyle) const;
216 : // deletes not necessary ranges if wanted
217 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
218 : bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow);
219 : void GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
220 : const sal_Int32 nTable, ScRowFormatRanges* pFormatRanges);
221 : void AddRangeStyleName(const com::sun::star::table::CellRangeAddress aCellRangeAddress, const sal_Int32 nStringIndex,
222 : const bool bIsAutoStyle, const sal_Int32 nValidationIndex, const sal_Int32 nNumberFormat);
223 : rtl::OUString* GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle);
224 : void Sort();
225 : };
226 :
227 : class ScColumnRowStylesBase
228 : {
229 : ScMyOUStringVec aStyleNames;
230 :
231 : public:
232 : ScColumnRowStylesBase();
233 : virtual ~ScColumnRowStylesBase();
234 :
235 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) = 0;
236 : sal_Int32 AddStyleName(rtl::OUString* pString);
237 : sal_Int32 GetIndexOfStyleName(const rtl::OUString& rString, const rtl::OUString& rPrefix);
238 : virtual rtl::OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField) = 0;
239 : rtl::OUString* GetStyleNameByIndex(const sal_Int32 nIndex);
240 : };
241 :
242 : struct ScColumnStyle
243 : {
244 : sal_Int32 nIndex;
245 : bool bIsVisible;
246 :
247 2050 : ScColumnStyle() : nIndex(-1), bIsVisible(true) {}
248 : };
249 :
250 : class ScColumnStyles : public ScColumnRowStylesBase
251 : {
252 : typedef std::vector<ScColumnStyle> ScMyColumnStyleVec;
253 : typedef std::vector<ScMyColumnStyleVec> ScMyColumnVectorVec;
254 : ScMyColumnVectorVec aTables;
255 :
256 : public:
257 : ScColumnStyles();
258 : ~ScColumnStyles();
259 :
260 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields);
261 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
262 : bool& bIsVisible);
263 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex, const bool bIsVisible);
264 : virtual rtl::OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField);
265 : };
266 :
267 : class ScRowStyles : public ScColumnRowStylesBase
268 : {
269 : typedef ::mdds::flat_segment_tree<sal_Int32, sal_Int32> StylesType;
270 : ::boost::ptr_vector<StylesType> aTables;
271 : struct Cache
272 : {
273 : sal_Int32 mnTable;
274 : sal_Int32 mnStart;
275 : sal_Int32 mnEnd;
276 : sal_Int32 mnStyle;
277 : Cache();
278 :
279 : bool hasCache(sal_Int32 nTable, sal_Int32 nField) const;
280 : };
281 : Cache maCache;
282 :
283 : public:
284 : ScRowStyles();
285 : ~ScRowStyles();
286 :
287 : virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields);
288 : sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField);
289 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex);
290 : void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField, const sal_Int32 nStringIndex, const sal_Int32 nEndField);
291 : virtual rtl::OUString* GetStyleName(const sal_Int32 nTable, const sal_Int32 nField);
292 : };
293 :
294 : #endif
295 :
296 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|