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 #ifndef SC_XMLSUBTI_HXX 24 #define SC_XMLSUBTI_HXX 25 26 #include <xmloff/xmlictxt.hxx> 27 #include <xmloff/xmlimp.hxx> 28 #include <com/sun/star/sheet/XSpreadsheet.hpp> 29 #include <com/sun/star/drawing/XDrawPage.hpp> 30 #include <com/sun/star/table/CellAddress.hpp> 31 #include <com/sun/star/table/XCellRange.hpp> 32 #include <com/sun/star/table/CellRangeAddress.hpp> 33 #include <com/sun/star/frame/XModel.hpp> 34 35 #include <vector> 36 #include <list> 37 #include "XMLTableShapeResizer.hxx" 38 #include "formula/grammar.hxx" 39 40 class ScXMLImport; 41 42 typedef std::vector<sal_Int32> ScMysalIntVec; 43 typedef std::list<sal_Int32> ScMysalIntList; 44 45 const ScMysalIntVec::size_type nDefaultRowCount = 20; 46 const ScMysalIntVec::size_type nDefaultColCount = 20; 47 const ScMysalIntVec::size_type nDefaultTabCount = 10; 48 49 class ScMyTableData 50 { 51 private: 52 com::sun::star::table::CellAddress aTableCellPos; 53 ScMysalIntVec nColsPerCol; 54 ScMysalIntVec nRealCols; 55 ScMysalIntVec nRowsPerRow; 56 ScMysalIntVec nRealRows; 57 sal_Int32 nSpannedCols; 58 sal_Int32 nColCount; 59 sal_Int32 nSubTableSpanned; 60 ScMysalIntList nChangedCols; 61 public: 62 ScMyTableData(sal_Int32 nSheet = -1, sal_Int32 nCol = -1, sal_Int32 nRow = -1); 63 ~ScMyTableData(); GetCellPos() const64 com::sun::star::table::CellAddress GetCellPos() const { return aTableCellPos; } GetRow() const65 sal_Int32 GetRow() const { return aTableCellPos.Row; } GetColumn() const66 sal_Int32 GetColumn() const { return aTableCellPos.Column; } 67 void AddRow(); 68 void AddColumn(); SetFirstColumn()69 void SetFirstColumn() { aTableCellPos.Column = -1; } GetColsPerCol(const sal_Int32 nIndex) const70 sal_Int32 GetColsPerCol(const sal_Int32 nIndex) const { return nColsPerCol[nIndex]; } SetColsPerCol(const sal_Int32 nIndex,sal_Int32 nValue=1)71 void SetColsPerCol(const sal_Int32 nIndex, sal_Int32 nValue = 1) { nColsPerCol[nIndex] = nValue; } 72 sal_Int32 GetRealCols(const sal_Int32 nIndex, const sal_Bool bIsNormal = sal_True) const; SetRealCols(const sal_Int32 nIndex,const sal_Int32 nValue)73 void SetRealCols(const sal_Int32 nIndex, const sal_Int32 nValue) { nRealCols[nIndex] = nValue; } GetRowsPerRow(const sal_Int32 nIndex) const74 sal_Int32 GetRowsPerRow(const sal_Int32 nIndex) const { return nRowsPerRow[nIndex]; } SetRowsPerRow(const sal_Int32 nIndex,const sal_Int32 nValue=1)75 void SetRowsPerRow(const sal_Int32 nIndex, const sal_Int32 nValue = 1) { nRowsPerRow[nIndex] = nValue; } GetRealRows(const sal_Int32 nIndex) const76 sal_Int32 GetRealRows(const sal_Int32 nIndex) const { return nIndex < 0 ? 0 : nRealRows[nIndex]; } SetRealRows(const sal_Int32 nIndex,const sal_Int32 nValue)77 void SetRealRows(const sal_Int32 nIndex, const sal_Int32 nValue) { nRealRows[nIndex] = nValue; } GetSpannedCols() const78 sal_Int32 GetSpannedCols() const { return nSpannedCols; } SetSpannedCols(const sal_Int32 nTempSpannedCols)79 void SetSpannedCols(const sal_Int32 nTempSpannedCols) { nSpannedCols = nTempSpannedCols; } GetColCount() const80 sal_Int32 GetColCount() const { return nColCount; } SetColCount(const sal_Int32 nTempColCount)81 void SetColCount(const sal_Int32 nTempColCount) { nColCount = nTempColCount; } GetSubTableSpanned() const82 sal_Int32 GetSubTableSpanned() const { return nSubTableSpanned; } SetSubTableSpanned(const sal_Int32 nValue)83 void SetSubTableSpanned(const sal_Int32 nValue) { nSubTableSpanned = nValue; } 84 sal_Int32 GetChangedCols(const sal_Int32 nFromIndex, const sal_Int32 nToIndex) const; 85 void SetChangedCols(const sal_Int32 nValue); 86 }; 87 88 //******************************************************************************************************************************* 89 90 struct ScMatrixRange 91 { 92 rtl::OUString sFormula; 93 rtl::OUString sFormulaNmsp; 94 formula::FormulaGrammar::Grammar eGrammar; 95 com::sun::star::table::CellRangeAddress aRange; ScMatrixRangeScMatrixRange96 ScMatrixRange(const com::sun::star::table::CellRangeAddress& rRange, const rtl::OUString& rFormula, const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammarP) : 97 sFormula(rFormula), 98 sFormulaNmsp(rFormulaNmsp), 99 eGrammar(eGrammarP), 100 aRange(rRange) 101 { 102 } 103 }; 104 105 class ScMyTables 106 { 107 private: 108 typedef std::list<ScMatrixRange> ScMyMatrixRangeList; 109 110 ScXMLImport& rImport; 111 112 ScMyShapeResizer aResizeShapes; 113 114 ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet > xCurrentSheet; 115 ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > xCurrentCellRange; 116 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > xDrawPage; 117 ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShapes > xShapes; 118 rtl::OUString sCurrentSheetName; 119 rtl::OUString sPassword; 120 std::vector<ScMyTableData*> aTableVec; 121 ScMyMatrixRangeList aMatrixRangeList; 122 com::sun::star::table::CellAddress aRealCellPos; 123 sal_Int32 nCurrentColStylePos; 124 sal_Int16 nCurrentDrawPage; 125 sal_Int16 nCurrentXShapes; 126 sal_Int32 nTableCount; 127 sal_Int32 nCurrentSheet; 128 sal_Bool bProtection; 129 130 sal_Bool IsMerged (const com::sun::star::uno::Reference <com::sun::star::table::XCellRange>& xCellRange, 131 const sal_Int32 nCol, const sal_Int32 nRow, 132 com::sun::star::table::CellRangeAddress& aCellAddress) const; 133 void UnMerge(); 134 void DoMerge(sal_Int32 nCount = -1); 135 void InsertRow(); 136 void NewRow(); 137 void InsertColumn(); 138 void NewColumn(sal_Bool bIsCovered); 139 public: 140 ScMyTables(ScXMLImport& rImport); 141 ~ScMyTables(); 142 void NewSheet(const rtl::OUString& sTableName, const rtl::OUString& sStyleName, 143 const sal_Bool bProtection, const rtl::OUString& sPassword); 144 void AddRow(); 145 void SetRowStyle(const rtl::OUString& rCellStyleName); 146 void AddColumn(sal_Bool bIsCovered); 147 void NewTable(sal_Int32 nTempSpannedCols); 148 void UpdateRowHeights(); ResizeShapes()149 void ResizeShapes() { aResizeShapes.ResizeShapes(); } 150 void DeleteTable(); 151 com::sun::star::table::CellAddress GetRealCellPos(); 152 void AddColCount(sal_Int32 nTempColCount); 153 void AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName); GetCurrentSheetName() const154 rtl::OUString GetCurrentSheetName() const { return sCurrentSheetName; } GetCurrentSheet() const155 sal_Int32 GetCurrentSheet() const { return nCurrentSheet; } GetCurrentColumn() const156 sal_Int32 GetCurrentColumn() const { return aTableVec[nTableCount - 1]->GetColCount(); } GetCurrentRow() const157 sal_Int32 GetCurrentRow() const { return aTableVec[nTableCount - 1]->GetRow(); } 158 ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet > GetCurrentXSheet()159 GetCurrentXSheet() { return xCurrentSheet; } 160 ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > GetCurrentXCellRange()161 GetCurrentXCellRange() { return xCurrentCellRange; } 162 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > 163 GetCurrentXDrawPage(); 164 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > 165 GetCurrentXShapes(); 166 sal_Bool HasDrawPage(); 167 sal_Bool HasXShapes(); 168 void AddShape(com::sun::star::uno::Reference <com::sun::star::drawing::XShape>& rShape, 169 rtl::OUString* pRangeList, 170 com::sun::star::table::CellAddress& rStartAddress, 171 com::sun::star::table::CellAddress& rEndAddress, 172 sal_Int32 nEndX, sal_Int32 nEndY); 173 174 void AddMatrixRange( sal_Int32 nStartColumn, 175 sal_Int32 nStartRow, 176 sal_Int32 nEndColumn, 177 sal_Int32 nEndRow, 178 const rtl::OUString& rFormula, 179 const rtl::OUString& rFormulaNmsp, 180 const formula::FormulaGrammar::Grammar ); 181 182 sal_Bool IsPartOfMatrix(sal_Int32 nColumn, sal_Int32 nRow); 183 void SetMatrix( const com::sun::star::table::CellRangeAddress& rRange, 184 const rtl::OUString& rFormula, 185 const rtl::OUString& rFormulaNmsp, 186 const formula::FormulaGrammar::Grammar ); 187 }; 188 189 #endif 190