1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_XMLSTYLESIMPORTHELPER_HXX 25 #define SC_XMLSTYLESIMPORTHELPER_HXX 26 27 #include "rangelst.hxx" 28 #include <rtl/ustring.hxx> 29 #include <com/sun/star/table/CellRangeAddress.hpp> 30 #include <com/sun/star/table/CellAddress.hpp> 31 32 #include <set> 33 #include <vector> 34 35 class ScXMLImport; 36 37 struct ScMyStyleNumberFormat 38 { 39 rtl::OUString sStyleName; 40 sal_Int32 nNumberFormat; 41 ScMyStyleNumberFormatScMyStyleNumberFormat42 ScMyStyleNumberFormat() : nNumberFormat(-1) {} ScMyStyleNumberFormatScMyStyleNumberFormat43 ScMyStyleNumberFormat(const rtl::OUString& rStyleName) : 44 sStyleName(rStyleName), nNumberFormat(-1) {} ScMyStyleNumberFormatScMyStyleNumberFormat45 ScMyStyleNumberFormat(const rtl::OUString& rStyleName, const sal_Int32 nFormat) : 46 sStyleName(rStyleName), nNumberFormat(nFormat) {} 47 }; 48 49 struct LessStyleNumberFormat 50 { operator ()LessStyleNumberFormat51 sal_Bool operator() (const ScMyStyleNumberFormat& rValue1, const ScMyStyleNumberFormat& rValue2) const 52 { 53 return rValue1.sStyleName < rValue2.sStyleName; 54 } 55 }; 56 57 typedef std::set< ScMyStyleNumberFormat, LessStyleNumberFormat > ScMyStyleNumberFormatSet; 58 59 class ScMyStyleNumberFormats 60 { 61 ScMyStyleNumberFormatSet aSet; 62 63 public: 64 void AddStyleNumberFormat(const rtl::OUString& rStyleName, const sal_Int32 nNumberFormat); 65 sal_Int32 GetStyleNumberFormat(const rtl::OUString& rStyleName); 66 }; 67 68 struct ScMyCurrencyStyle 69 { 70 rtl::OUString sCurrency; 71 ScRangeListRef xRanges; 72 ScMyCurrencyStyleScMyCurrencyStyle73 ScMyCurrencyStyle() : xRanges(new ScRangeList()) {} ~ScMyCurrencyStyleScMyCurrencyStyle74 ~ScMyCurrencyStyle() {} 75 }; 76 77 struct LessCurrencyStyle 78 { operator ()LessCurrencyStyle79 sal_Bool operator() (const ScMyCurrencyStyle& rValue1, const ScMyCurrencyStyle& rValue2) const 80 { 81 return rValue1.sCurrency < rValue2.sCurrency; 82 } 83 }; 84 85 typedef std::set<ScMyCurrencyStyle, LessCurrencyStyle> ScMyCurrencyStylesSet; 86 87 class ScMyStyleRanges : public SvRefBase 88 { 89 ScRangeList* pTextList; 90 ScRangeList* pNumberList; 91 ScRangeList* pTimeList; 92 ScRangeList* pDateTimeList; 93 ScRangeList* pPercentList; 94 ScRangeList* pLogicalList; 95 ScRangeList* pUndefinedList; 96 ScMyCurrencyStylesSet* pCurrencyList; 97 98 void AddRange(const ScRange& rRange, ScRangeList* pList, 99 const rtl::OUString* pStyleName, const sal_Int16 nType, 100 ScXMLImport& rImport, const sal_uInt32 nMaxRanges); 101 void AddCurrencyRange(const ScRange& rRange, ScRangeListRef xList, 102 const rtl::OUString* pStyleName, const rtl::OUString* pCurrency, 103 ScXMLImport& rImport, const sal_uInt32 nMaxRanges); 104 void InsertColRow(const ScRange& rRange, const SCsCOL nDx, const SCsROW nDy, 105 const SCsTAB nDz, ScDocument* pDoc); 106 void SetStylesToRanges(ScRangeList* pList, 107 const rtl::OUString* pStyleName, const sal_Int16 nCellType, 108 const rtl::OUString* pCurrency, ScXMLImport& rImport); 109 void SetStylesToRanges(ScRangeListRef xList, 110 const rtl::OUString* pStyleName, const sal_Int16 nCellType, 111 const rtl::OUString* pCurrency, ScXMLImport& rImport); 112 public: 113 ScMyStyleRanges(); 114 ~ScMyStyleRanges(); 115 void AddRange(const ScRange& rRange, 116 const rtl::OUString* pStyleName, const sal_Int16 nType, 117 ScXMLImport& rImport, const sal_uInt32 nMaxRanges); 118 void AddCurrencyRange(const ScRange& rRange, 119 const rtl::OUString* pStyleName, const rtl::OUString* pCurrency, 120 ScXMLImport& rImport, const sal_uInt32 nMaxRanges); 121 void InsertRow(const sal_Int32 nRow, const sal_Int32 nTab, ScDocument* pDoc); 122 void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc); 123 void SetStylesToRanges(const rtl::OUString* pStyleName, ScXMLImport& rImport); 124 }; 125 SV_DECL_IMPL_REF( ScMyStyleRanges ); 126 127 struct ScMyStyle 128 { 129 rtl::OUString sStyleName; 130 ScMyStyleRangesRef xRanges; 131 ScMyStyleScMyStyle132 ScMyStyle() : xRanges(new ScMyStyleRanges()) {} ~ScMyStyleScMyStyle133 ~ScMyStyle() {} 134 }; 135 136 struct LessStyle 137 { operator ()LessStyle138 sal_Bool operator() (const ScMyStyle& rValue1, const ScMyStyle& rValue2) const 139 { 140 return rValue1.sStyleName < rValue2.sStyleName; 141 } 142 }; 143 144 typedef std::set<ScMyStyle, LessStyle> ScMyStylesSet; 145 typedef std::vector<ScMyStylesSet::iterator> ScMyStyles; 146 147 class ScMyStylesImportHelper 148 { 149 ScMyStylesSet aCellStyles; 150 ScMyStyles aColDefaultStyles; 151 ScMyStylesSet::iterator aRowDefaultStyle; 152 ScXMLImport& rImport; 153 rtl::OUString* pStyleName; 154 rtl::OUString* pPrevStyleName; 155 rtl::OUString* pCurrency; 156 rtl::OUString* pPrevCurrency; 157 ScRange aPrevRange; 158 sal_uInt32 nMaxRanges; 159 sal_Int16 nCellType; 160 sal_Int16 nPrevCellType; 161 sal_Bool bPrevRangeAdded; 162 163 void ResetAttributes(); 164 ScMyStylesSet::iterator GetIterator(const rtl::OUString* pStyleName); 165 void AddDefaultRange(const ScRange& rRange); 166 void AddSingleRange(const ScRange& rRange); 167 void AddRange(); IsEqual(const rtl::OUString * pFirst,const rtl::OUString * pSecond)168 sal_Bool IsEqual(const rtl::OUString* pFirst, const rtl::OUString* pSecond) 169 { 170 return ((pFirst && pSecond && pFirst->equals(*pSecond)) || 171 (!pFirst && !pSecond) || 172 (!pFirst && pSecond && !pSecond->getLength()) || 173 (!pSecond && pFirst && !pFirst->getLength())); 174 } 175 public: 176 ScMyStylesImportHelper(ScXMLImport& rImport); 177 ~ScMyStylesImportHelper(); 178 void AddColumnStyle(const rtl::OUString& rStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat); 179 void SetRowStyle(const rtl::OUString& rStyleName); 180 void SetAttributes(rtl::OUString* pStyleName, 181 rtl::OUString* pCurrency, const sal_Int16 nCellType); 182 void AddRange(const ScRange& rRange); 183 void AddCell(const com::sun::star::table::CellAddress& rAddress); 184 void InsertRow(const sal_Int32 nRow, const sal_Int32 nTab, ScDocument* pDoc); // a row is inserted before nRow 185 void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc); // a col is inserted before nCol 186 void EndTable(); 187 void SetStylesToRanges(); 188 }; 189 190 #endif 191 192