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 177 : struct ScMyStyleNumberFormat
35 : {
36 : rtl::OUString sStyleName;
37 : sal_Int32 nNumberFormat;
38 :
39 : ScMyStyleNumberFormat() : nNumberFormat(-1) {}
40 77 : ScMyStyleNumberFormat(const rtl::OUString& rStyleName) :
41 77 : sStyleName(rStyleName), nNumberFormat(-1) {}
42 52 : ScMyStyleNumberFormat(const rtl::OUString& rStyleName, const sal_Int32 nFormat) :
43 52 : sStyleName(rStyleName), nNumberFormat(nFormat) {}
44 : };
45 :
46 : struct LessStyleNumberFormat
47 : {
48 172 : bool operator() (const ScMyStyleNumberFormat& rValue1, const ScMyStyleNumberFormat& rValue2) const
49 : {
50 172 : return rValue1.sStyleName < rValue2.sStyleName;
51 : }
52 : };
53 :
54 : typedef std::set< ScMyStyleNumberFormat, LessStyleNumberFormat > ScMyStyleNumberFormatSet;
55 :
56 44 : class ScMyStyleNumberFormats
57 : {
58 : ScMyStyleNumberFormatSet aSet;
59 :
60 : public:
61 : void AddStyleNumberFormat(const rtl::OUString& rStyleName, const sal_Int32 nNumberFormat);
62 : sal_Int32 GetStyleNumberFormat(const rtl::OUString& rStyleName);
63 : };
64 :
65 1 : struct ScMyCurrencyStyle
66 : {
67 : rtl::OUString sCurrency;
68 : ::boost::shared_ptr<ScSimpleRangeList> mpRanges;
69 :
70 1 : ScMyCurrencyStyle() :
71 1 : mpRanges(new ScSimpleRangeList)
72 1 : {}
73 2 : ~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 rtl::OUString* pStyleName, const sal_Int16 nCellType,
99 : const rtl::OUString* pCurrency, ScXMLImport& rImport);
100 : public:
101 : ScMyStyleRanges();
102 : ~ScMyStyleRanges();
103 : void AddRange(const ScRange& rRange,
104 : const rtl::OUString* pStyleName, const sal_Int16 nType,
105 : ScXMLImport& rImport, const sal_uInt32 nMaxRanges);
106 : void AddCurrencyRange(const ScRange& rRange,
107 : const rtl::OUString* pStyleName, const rtl::OUString* pCurrency,
108 : ScXMLImport& rImport, const sal_uInt32 nMaxRanges);
109 : void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc);
110 : void SetStylesToRanges(const rtl::OUString* pStyleName, ScXMLImport& rImport);
111 : };
112 11884 : SV_DECL_IMPL_REF( ScMyStyleRanges );
113 :
114 194 : struct ScMyStyle
115 : {
116 : rtl::OUString sStyleName;
117 : ScMyStyleRangesRef xRanges;
118 :
119 4093 : ScMyStyle() : xRanges(new ScMyStyleRanges()) {}
120 4287 : ~ScMyStyle() {}
121 : };
122 :
123 : struct LessStyle
124 : {
125 12842 : bool operator() (const ScMyStyle& rValue1, const ScMyStyle& rValue2) const
126 : {
127 12842 : return rValue1.sStyleName < rValue2.sStyleName;
128 : }
129 : };
130 :
131 : typedef std::set<ScMyStyle, LessStyle> ScMyStylesSet;
132 : typedef std::vector<ScMyStylesSet::iterator> ScMyStyles;
133 :
134 : class ScMyStylesImportHelper
135 : {
136 : ScMyStylesSet aCellStyles;
137 : ScMyStyles aColDefaultStyles;
138 : ScMyStylesSet::iterator aRowDefaultStyle;
139 : ScXMLImport& rImport;
140 : rtl::OUString* pStyleName;
141 : rtl::OUString* pPrevStyleName;
142 : rtl::OUString* pCurrency;
143 : rtl::OUString* pPrevCurrency;
144 : ScRange aPrevRange;
145 : sal_uInt32 nMaxRanges;
146 : sal_Int16 nCellType;
147 : sal_Int16 nPrevCellType;
148 : bool bPrevRangeAdded;
149 :
150 : void ResetAttributes();
151 : ScMyStylesSet::iterator GetIterator(const rtl::OUString* pStyleName);
152 : void AddDefaultRange(const ScRange& rRange);
153 : void AddSingleRange(const ScRange& rRange);
154 : void AddRange();
155 1566 : bool IsEqual(const rtl::OUString* pFirst, const rtl::OUString* pSecond)
156 : {
157 62 : return ((pFirst && pSecond && pFirst->equals(*pSecond)) ||
158 : (!pFirst && !pSecond) ||
159 43 : (!pFirst && pSecond && !pSecond->getLength()) ||
160 1671 : (!pSecond && pFirst && !pFirst->getLength()));
161 : }
162 : public:
163 : ScMyStylesImportHelper(ScXMLImport& rImport);
164 : ~ScMyStylesImportHelper();
165 : void AddColumnStyle(const rtl::OUString& rStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat);
166 : void SetRowStyle(const rtl::OUString& rStyleName);
167 : void SetAttributes(rtl::OUString* pStyleName,
168 : rtl::OUString* pCurrency, const sal_Int16 nCellType);
169 : void AddRange(const ScRange& rRange);
170 : void AddCell(const ScAddress& rAddress);
171 : void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc); // a col is inserted before nCol
172 : void EndTable();
173 : void SetStylesToRanges();
174 : };
175 :
176 : #endif
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|