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_XMLSTYLESIMPORTHELPER_HXX
21 : #define SC_XMLSTYLESIMPORTHELPER_HXX
22 :
23 : #include "rangelst.hxx"
24 : #include "simplerangelist.hxx"
25 : #include <rtl/ustring.hxx>
26 :
27 : #include <set>
28 : #include <vector>
29 : #include <list>
30 : #include <boost/shared_ptr.hpp>
31 :
32 : class ScXMLImport;
33 :
34 718 : struct ScMyStyleNumberFormat
35 : {
36 : OUString sStyleName;
37 : sal_Int32 nNumberFormat;
38 :
39 : ScMyStyleNumberFormat() : nNumberFormat(-1) {}
40 304 : ScMyStyleNumberFormat(const OUString& rStyleName) :
41 304 : sStyleName(rStyleName), nNumberFormat(-1) {}
42 184 : ScMyStyleNumberFormat(const OUString& rStyleName, const sal_Int32 nFormat) :
43 184 : sStyleName(rStyleName), nNumberFormat(nFormat) {}
44 : };
45 :
46 : struct LessStyleNumberFormat
47 : {
48 566 : bool operator() (const ScMyStyleNumberFormat& rValue1, const ScMyStyleNumberFormat& rValue2) const
49 : {
50 566 : return rValue1.sStyleName < rValue2.sStyleName;
51 : }
52 : };
53 :
54 : typedef std::set< ScMyStyleNumberFormat, LessStyleNumberFormat > ScMyStyleNumberFormatSet;
55 :
56 212 : class ScMyStyleNumberFormats
57 : {
58 : ScMyStyleNumberFormatSet aSet;
59 :
60 : public:
61 : void AddStyleNumberFormat(const OUString& rStyleName, const sal_Int32 nNumberFormat);
62 : sal_Int32 GetStyleNumberFormat(const OUString& rStyleName);
63 : };
64 :
65 5 : struct ScMyCurrencyStyle
66 : {
67 : OUString sCurrency;
68 : ::boost::shared_ptr<ScSimpleRangeList> mpRanges;
69 :
70 5 : ScMyCurrencyStyle() :
71 5 : mpRanges(new ScSimpleRangeList)
72 5 : {}
73 10 : ~ScMyCurrencyStyle() {}
74 : };
75 :
76 : struct LessCurrencyStyle
77 : {
78 0 : bool operator() (const ScMyCurrencyStyle& rValue1, const ScMyCurrencyStyle& rValue2) const
79 : {
80 0 : return rValue1.sCurrency < rValue2.sCurrency;
81 : }
82 : };
83 :
84 : typedef std::set<ScMyCurrencyStyle, LessCurrencyStyle> ScMyCurrencyStylesSet;
85 :
86 : class ScMyStyleRanges : public SvRefBase
87 : {
88 : ::boost::shared_ptr<ScSimpleRangeList> mpTextList;
89 : ::boost::shared_ptr<ScSimpleRangeList> mpNumberList;
90 : ::boost::shared_ptr<ScSimpleRangeList> mpTimeList;
91 : ::boost::shared_ptr<ScSimpleRangeList> mpDateTimeList;
92 : ::boost::shared_ptr<ScSimpleRangeList> mpPercentList;
93 : ::boost::shared_ptr<ScSimpleRangeList> mpLogicalList;
94 : ::boost::shared_ptr<ScSimpleRangeList> mpUndefinedList;
95 : ScMyCurrencyStylesSet* pCurrencyList;
96 :
97 : void SetStylesToRanges(const ::std::list<ScRange>& rList,
98 : const OUString* pStyleName, const sal_Int16 nCellType,
99 : const OUString* pCurrency, ScXMLImport& rImport);
100 : public:
101 : ScMyStyleRanges();
102 : virtual ~ScMyStyleRanges();
103 : void AddRange(const ScRange& rRange, const sal_Int16 nType);
104 : void AddCurrencyRange(const ScRange& rRange, const OUString* pCurrency);
105 : void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc);
106 : void SetStylesToRanges(const OUString* pStyleName, ScXMLImport& rImport);
107 : };
108 : typedef tools::SvRef<ScMyStyleRanges> ScMyStyleRangesRef;
109 :
110 873 : struct ScMyStyle
111 : {
112 : OUString sStyleName;
113 : ScMyStyleRangesRef xRanges;
114 :
115 9670 : ScMyStyle() : xRanges(new ScMyStyleRanges()) {}
116 10543 : ~ScMyStyle() {}
117 : };
118 :
119 : struct LessStyle
120 : {
121 34929 : bool operator() (const ScMyStyle& rValue1, const ScMyStyle& rValue2) const
122 : {
123 34929 : return rValue1.sStyleName < rValue2.sStyleName;
124 : }
125 : };
126 :
127 : typedef std::set<ScMyStyle, LessStyle> ScMyStylesSet;
128 : typedef std::vector<ScMyStylesSet::iterator> ScMyStyles;
129 :
130 : class ScMyStylesImportHelper
131 : {
132 : ScMyStylesSet aCellStyles;
133 : ScMyStyles aColDefaultStyles;
134 : ScMyStylesSet::iterator aRowDefaultStyle;
135 : ScXMLImport& rImport;
136 : OUString* pStyleName;
137 : OUString* pPrevStyleName;
138 : OUString* pCurrency;
139 : OUString* pPrevCurrency;
140 : ScRange aPrevRange;
141 : sal_Int16 nCellType;
142 : sal_Int16 nPrevCellType;
143 : bool bPrevRangeAdded;
144 :
145 : void ResetAttributes();
146 : ScMyStylesSet::iterator GetIterator(const OUString* pStyleName);
147 : void AddDefaultRange(const ScRange& rRange);
148 : void AddSingleRange(const ScRange& rRange);
149 : void AddRange();
150 6452 : bool IsEqual(const OUString* pFirst, const OUString* pSecond)
151 : {
152 870 : return ((pFirst && pSecond && pFirst->equals(*pSecond)) ||
153 5582 : (!pFirst && !pSecond) ||
154 12480 : (!pFirst && pSecond && pSecond->isEmpty()) ||
155 6694 : (!pSecond && pFirst && pFirst->isEmpty()));
156 : }
157 : public:
158 : ScMyStylesImportHelper(ScXMLImport& rImport);
159 : ~ScMyStylesImportHelper();
160 : void AddColumnStyle(const OUString& rStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat);
161 : void SetRowStyle(const OUString& rStyleName);
162 : void SetAttributes(OUString* pStyleName,
163 : OUString* pCurrency, const sal_Int16 nCellType);
164 : void AddRange(const ScRange& rRange);
165 : void AddCell(const ScAddress& rAddress);
166 : void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc); // a col is inserted before nCol
167 : void EndTable();
168 : void SetStylesToRanges();
169 : };
170 :
171 : #endif
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|