update ooo310-m15
[ooovba.git] / sc / source / filter / xml / xmlsubti.cxx
blob3a001e9e78fed72a3f421d513a8eb9e37699654f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlsubti.cxx,v $
10 * $Revision: 1.50.30.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 // INCLUDE ---------------------------------------------------------------
36 #include "xmlsubti.hxx"
37 #include "global.hxx"
38 #include "xmlstyli.hxx"
39 #include "xmlimprt.hxx"
40 #include "document.hxx"
41 #include "XMLConverter.hxx"
42 #include "docuno.hxx"
43 #include "cellsuno.hxx"
44 #include "XMLStylesImportHelper.hxx"
45 #include "tabprotection.hxx"
47 #include <xmloff/xmltkmap.hxx>
48 #include <xmloff/nmspmap.hxx>
49 #include <xmloff/xmluconv.hxx>
50 #include <xmloff/xmlerror.hxx>
51 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
52 #include <com/sun/star/util/XMergeable.hpp>
53 #include <com/sun/star/sheet/XSheetCellRange.hpp>
54 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
55 #include <com/sun/star/sheet/CellInsertMode.hpp>
56 #include <com/sun/star/sheet/XCellRangeMovement.hpp>
57 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
58 #include <com/sun/star/container/XNamed.hpp>
59 #include <com/sun/star/util/XProtectable.hpp>
60 #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
62 #include <memory>
64 using ::std::auto_ptr;
66 //------------------------------------------------------------------
68 using namespace com::sun::star;
70 ScMyTableData::ScMyTableData(sal_Int32 nSheet, sal_Int32 nCol, sal_Int32 nRow)
71 : nColsPerCol(nDefaultColCount, 1),
72 nRealCols(nDefaultColCount + 1, 0),
73 nRowsPerRow(nDefaultRowCount, 1),
74 nRealRows(nDefaultRowCount + 1, 0),
75 nChangedCols()
77 aTableCellPos.Sheet = sal::static_int_cast<sal_Int16>( nSheet );
78 aTableCellPos.Column = nCol;
79 aTableCellPos.Row = nRow;
81 for (sal_Int32 i = 0; i < 3; ++i)
82 nRealCols[i] = i;
83 for (sal_Int32 j = 0; j < 3; ++j)
84 nRealRows[j] = j;
86 nSpannedCols = 1;
87 nColCount = 0;
88 nSubTableSpanned = 1;
91 ScMyTableData::~ScMyTableData()
95 void ScMyTableData::AddRow()
97 ++aTableCellPos.Row;
98 if (static_cast<sal_uInt32>(aTableCellPos.Row) >= nRowsPerRow.size())
100 nRowsPerRow.resize(nRowsPerRow.size() + nDefaultRowCount, 1);
101 nRealRows.resize(nRowsPerRow.size() + nDefaultRowCount + 1, 0);
103 nRealRows[aTableCellPos.Row + 1] = nRealRows[aTableCellPos.Row] + nRowsPerRow[aTableCellPos.Row];
106 void ScMyTableData::AddColumn()
108 ++aTableCellPos.Column;
109 if (static_cast<sal_uInt32>(aTableCellPos.Column) >= nColsPerCol.size())
111 nColsPerCol.resize(nColsPerCol.size() + nDefaultColCount, 1);
112 nRealCols.resize(nColsPerCol.size() + nDefaultColCount + 1, 0);
114 nRealCols[aTableCellPos.Column + 1] = nRealCols[aTableCellPos.Column] + nColsPerCol[aTableCellPos.Column];
117 sal_Int32 ScMyTableData::GetRealCols(const sal_Int32 nIndex, const sal_Bool /* bIsNormal */) const
119 return (nIndex < 0) ? 0 : nRealCols[nIndex];
122 sal_Int32 ScMyTableData::GetChangedCols(const sal_Int32 nFromIndex, const sal_Int32 nToIndex) const
124 ScMysalIntList::const_iterator i(nChangedCols.begin());
125 ScMysalIntList::const_iterator endi(nChangedCols.end());
126 while ((i != endi) && ((*i < nToIndex) && !(*i >= nFromIndex)))
127 ++i;
128 if (i == endi)
129 return -1;
130 else
131 if ((*i >= nFromIndex) && (*i < nToIndex))
132 return *i;
133 else
134 return -1;
137 void ScMyTableData::SetChangedCols(const sal_Int32 nValue)
139 ScMysalIntList::iterator i(nChangedCols.begin());
140 ScMysalIntList::iterator endi(nChangedCols.end());
141 while ((i != endi) && (*i < nValue))
143 ++i;
145 if ((i == endi) || (*i != nValue))
146 nChangedCols.insert(i, nValue);
149 /*******************************************************************************************************************************/
151 ScXMLTabProtectionData::ScXMLTabProtectionData() :
152 meHash1(PASSHASH_UNSPECIFIED),
153 meHash2(PASSHASH_UNSPECIFIED),
154 mbProtected(false),
155 mbSelectProtectedCells(false),
156 mbSelectUnprotectedCells(false)
160 ScMyTables::ScMyTables(ScXMLImport& rTempImport)
161 : rImport(rTempImport),
162 aResizeShapes(rTempImport),
163 nCurrentColStylePos(0),
164 nCurrentDrawPage( -1 ),
165 nCurrentXShapes( -1 ),
166 nTableCount( 0 ),
167 nCurrentSheet( -1 )
169 aTableVec.resize(nDefaultTabCount, NULL);
172 ScMyTables::~ScMyTables()
174 ScMyTableData* pTable;
175 while (nTableCount > 0)
177 pTable = aTableVec[nTableCount - 1];
178 delete pTable;
179 aTableVec[nTableCount - 1] = NULL;
180 --nTableCount;
184 void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString& sStyleName,
185 const ScXMLTabProtectionData& rProtectData)
187 if (rImport.GetModel().is())
189 nCurrentColStylePos = 0;
190 sCurrentSheetName = sTableName;
191 ScMyTableData* aTable;
192 while (nTableCount > 0)
194 aTable = aTableVec[nTableCount - 1];
195 delete aTable;
196 aTableVec[nTableCount - 1] = NULL;
197 --nTableCount;
199 ++nCurrentSheet;
201 maProtectionData = rProtectData;
202 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( rImport.GetModel(), uno::UNO_QUERY );
203 if ( xSpreadDoc.is() )
205 uno::Reference <sheet::XSpreadsheets> xSheets(xSpreadDoc->getSheets());
206 if (xSheets.is())
208 if (nCurrentSheet > 0)
212 xSheets->insertNewByName(sTableName, sal::static_int_cast<sal_Int16>(nCurrentSheet));
214 catch ( uno::RuntimeException& )
216 ScDocument *pDoc = ScXMLConverter::GetScDocument(rImport.GetModel());
217 if (pDoc)
219 rImport.LockSolarMutex();
220 String sTabName(String::CreateFromAscii("Table"));
221 pDoc->CreateValidTabName(sTabName);
222 rtl::OUString sOUTabName(sTabName);
223 xSheets->insertNewByName(sOUTabName, sal::static_int_cast<sal_Int16>(nCurrentSheet));
224 rImport.UnlockSolarMutex();
228 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
229 if ( xIndex.is() )
231 xCurrentSheet.set(xIndex->getByIndex(nCurrentSheet), uno::UNO_QUERY);
232 if ( xCurrentSheet.is() )
234 xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY);
235 if (!(nCurrentSheet > 0))
237 uno::Reference < container::XNamed > xNamed(xCurrentSheet, uno::UNO_QUERY );
238 if ( xNamed.is() )
241 xNamed->setName(sTableName);
243 catch ( uno::RuntimeException& )
245 ScDocument *pDoc = ScXMLConverter::GetScDocument(rImport.GetModel());
246 if (pDoc)
248 rImport.LockSolarMutex();
249 String sTabName(String::CreateFromAscii("Table"));
250 pDoc->CreateValidTabName(sTabName);
251 rtl::OUString sOUTabName(sTabName);
252 xNamed->setName(sOUTabName);
253 rImport.UnlockSolarMutex();
257 rImport.SetTableStyle(sStyleName);
259 if ( sStyleName.getLength() )
261 // #i57869# All table style properties for all sheets are now applied here,
262 // before importing the contents.
263 // This is needed for the background color.
264 // Sheet visibility has special handling in ScDocFunc::SetTableVisible to
265 // allow hiding the first sheet.
266 // RTL layout is only remembered, not actually applied, so the shapes can
267 // be loaded before mirroring.
269 uno::Reference <beans::XPropertySet> xProperties(xCurrentSheet, uno::UNO_QUERY);
270 if (xProperties.is())
272 XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rImport.GetAutoStyles();
273 if (pStyles)
275 XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext(
276 XML_STYLE_FAMILY_TABLE_TABLE, sStyleName, sal_True);
277 if (pStyle)
278 pStyle->FillPropertySet(xProperties);
289 NewTable(1);
292 sal_Bool ScMyTables::IsMerged (const uno::Reference <table::XCellRange>& xCellRange, const sal_Int32 nCol, const sal_Int32 nRow,
293 table::CellRangeAddress& aCellAddress) const
295 uno::Reference <util::XMergeable> xMergeable (xCellRange->getCellRangeByPosition(nCol,nRow,nCol,nRow), uno::UNO_QUERY);
296 if (xMergeable.is())
298 uno::Reference<sheet::XSheetCellRange> xMergeSheetCellRange (xMergeable, uno::UNO_QUERY);
299 uno::Reference<sheet::XSpreadsheet> xTable(xMergeSheetCellRange->getSpreadsheet());
300 uno::Reference<sheet::XSheetCellCursor> xMergeSheetCursor(xTable->createCursorByRange(xMergeSheetCellRange));
301 if (xMergeSheetCursor.is())
303 xMergeSheetCursor->collapseToMergedArea();
304 uno::Reference<sheet::XCellRangeAddressable> xMergeCellAddress (xMergeSheetCursor, uno::UNO_QUERY);
305 if (xMergeCellAddress.is())
307 aCellAddress = xMergeCellAddress->getRangeAddress();
308 if (aCellAddress.StartColumn == nCol && aCellAddress.EndColumn == nCol &&
309 aCellAddress.StartRow == nRow && aCellAddress.EndRow == nRow)
310 return sal_False;
311 else
312 return sal_True;
316 return sal_False;
319 void ScMyTables::UnMerge()
321 if ( xCurrentCellRange.is() )
323 table::CellRangeAddress aCellAddress;
324 if (IsMerged(xCurrentCellRange, GetRealCellPos().Column, GetRealCellPos().Row, aCellAddress))
326 //unmerge
327 uno::Reference <util::XMergeable> xMergeable (xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
328 aCellAddress.EndColumn, aCellAddress.EndRow), uno::UNO_QUERY);
329 if (xMergeable.is())
330 xMergeable->merge(sal_False);
335 void ScMyTables::DoMerge(sal_Int32 nCount)
337 if ( xCurrentCellRange.is() )
339 table::CellRangeAddress aCellAddress;
340 if (IsMerged(xCurrentCellRange, GetRealCellPos().Column, GetRealCellPos().Row, aCellAddress))
342 //unmerge
343 uno::Reference <util::XMergeable> xMergeable (xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
344 aCellAddress.EndColumn, aCellAddress.EndRow), uno::UNO_QUERY);
345 if (xMergeable.is())
346 xMergeable->merge(sal_False);
349 //merge
350 uno::Reference <table::XCellRange> xMergeCellRange;
351 if (nCount == -1)
352 xMergeCellRange.set(xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
353 aCellAddress.EndColumn
354 + aTableVec[nTableCount - 1]->GetColsPerCol(aTableVec[nTableCount - 1]->GetColumn()) - 1,
355 aCellAddress.EndRow
356 + aTableVec[nTableCount - 1]->GetRowsPerRow(aTableVec[nTableCount - 1]->GetRow()) - 1));
357 else
358 xMergeCellRange.set(xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
359 aCellAddress.StartColumn
360 + nCount - 1,
361 aCellAddress.EndRow));
362 uno::Reference <util::XMergeable> xMergeable (xMergeCellRange, uno::UNO_QUERY);
363 if (xMergeable.is())
364 xMergeable->merge(sal_True);
368 void ScMyTables::InsertRow()
370 if ( xCurrentCellRange.is() )
372 table::CellRangeAddress aCellAddress;
373 sal_Int32 nRow(GetRealCellPos().Row);
374 for (sal_Int32 j = 0; j < GetRealCellPos().Column - aTableVec[nTableCount - 1]->GetColumn() - 1; ++j)
376 if (IsMerged(xCurrentCellRange, j, nRow - 1, aCellAddress))
378 //unmerge
379 uno::Reference <util::XMergeable> xMergeable (xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
380 aCellAddress.EndColumn, aCellAddress.EndRow), uno::UNO_QUERY);
381 if (xMergeable.is())
382 xMergeable->merge(sal_False);
385 //merge
386 uno::Reference <util::XMergeable> xMergeable (xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
387 aCellAddress.EndColumn, aCellAddress.EndRow + 1), uno::UNO_QUERY);
388 if (xMergeable.is())
389 xMergeable->merge(sal_True);
390 j += aCellAddress.EndColumn - aCellAddress.StartColumn;
392 rImport.GetStylesImportHelper()->InsertRow(nRow, nCurrentSheet, rImport.GetDocument());
396 void ScMyTables::NewRow()
398 if (nTableCount > 1)
399 if (aTableVec[nTableCount - 1]->GetRealRows(aTableVec[nTableCount - 1]->GetRow()) >
400 aTableVec[nTableCount - 2]->GetRowsPerRow(aTableVec[nTableCount - 2]->GetRow()) - 1)
402 if (GetRealCellPos().Column > 0)
403 InsertRow();
404 for (sal_Int16 i = sal::static_int_cast<sal_Int16>(nTableCount - 1); i > 0; i--)
406 sal_Int32 nRow = aTableVec[i - 1]->GetRow();
407 aTableVec[i - 1]->SetRowsPerRow(nRow,
408 aTableVec[i - 1]->GetRowsPerRow(nRow) + 1);
409 aTableVec[i - 1]->SetRealRows(nRow + 1,
410 aTableVec[i - 1]->GetRealRows(nRow)
411 + aTableVec[i - 1]->GetRowsPerRow(nRow));
416 void ScMyTables::AddRow()
418 aTableVec[nTableCount - 1]->AddRow();
419 aTableVec[nTableCount - 1]->SetFirstColumn();
420 sal_Int32 nRow = aTableVec[nTableCount - 1]->GetRow();
421 if (nRow > 0)
422 NewRow();
423 aTableVec[nTableCount - 1]->SetRealRows(nRow + 1,
424 aTableVec[nTableCount - 1]->GetRealRows(nRow)
425 + aTableVec[nTableCount - 1]->GetRowsPerRow(nRow));
428 void ScMyTables::SetRowStyle(const rtl::OUString& rCellStyleName)
430 rImport.GetStylesImportHelper()->SetRowStyle(rCellStyleName);
433 void ScMyTables::InsertColumn()
435 if ( xCurrentCellRange.is() )
437 table::CellRangeAddress aCellAddress;
438 sal_Int32 nCol(GetRealCellPos().Column);
439 for (sal_Int32 j = 0; j <= GetRealCellPos().Row - aTableVec[nTableCount - 1]->GetRow() - 1; ++j)
441 table::CellRangeAddress aTempCellAddress;
442 if (IsMerged(xCurrentCellRange, nCol - 1, j, aCellAddress))
444 //unmerge
445 uno::Reference <util::XMergeable> xMergeable (xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
446 aCellAddress.EndColumn, aCellAddress.EndRow), uno::UNO_QUERY);
447 if (xMergeable.is())
448 xMergeable->merge(sal_False);
449 aTempCellAddress = aCellAddress;
450 aTempCellAddress.StartColumn = aTempCellAddress.EndColumn + 1;
451 aTempCellAddress.EndColumn = aTempCellAddress.StartColumn;
453 else
455 aTempCellAddress = aCellAddress;
456 aTempCellAddress.StartColumn += 1;
457 aTempCellAddress.EndColumn = aTempCellAddress.StartColumn;
460 //insert Cell
461 sheet::CellInsertMode aCellInsertMode(sheet::CellInsertMode_RIGHT);
462 uno::Reference <sheet::XCellRangeMovement> xCellRangeMovement (xCurrentSheet, uno::UNO_QUERY);
463 xCellRangeMovement->insertCells(aTempCellAddress, aCellInsertMode);
465 //merge
466 uno::Reference <util::XMergeable> xMergeable (xCurrentCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
467 aCellAddress.EndColumn + 1, aCellAddress.EndRow), uno::UNO_QUERY);
468 if (xMergeable.is())
469 xMergeable->merge(sal_True);
470 j += aCellAddress.EndRow - aCellAddress.StartRow;
472 rImport.GetStylesImportHelper()->InsertCol(nCol, nCurrentSheet, rImport.GetDocument());
476 void ScMyTables::NewColumn(sal_Bool bIsCovered)
478 if (!bIsCovered)
480 sal_Int32 nColCount(aTableVec[nTableCount - 1]->GetColCount());
481 sal_Int32 nSpannedCols(aTableVec[nTableCount - 1]->GetSpannedCols());
482 if ( (nSpannedCols > nColCount) &&
483 (aTableVec[nTableCount - 1]->GetRow() == 0) &&
484 (aTableVec[nTableCount - 1]->GetColumn() == 0) )
486 if (nColCount > 0)
488 sal_Int32 FirstColsSpanned(nSpannedCols / nColCount);
489 sal_Int32 LastColSpanned(FirstColsSpanned
490 + (nSpannedCols % nColCount));
491 for (sal_Int32 i = 0; i < nColCount - 1; ++i)
493 aTableVec[nTableCount - 1]->SetColsPerCol(i, FirstColsSpanned);
494 aTableVec[nTableCount - 1]->SetRealCols(i + 1,
495 aTableVec[nTableCount - 1]->GetRealCols(i)
496 + FirstColsSpanned);
498 aTableVec[nTableCount - 1]->SetColsPerCol(nColCount - 1, LastColSpanned);
499 aTableVec[nTableCount - 1]->SetRealCols(nColCount - 1 + 1,
500 aTableVec[nTableCount - 1]->GetRealCols(nColCount - 1)
501 + LastColSpanned);
504 if (aTableVec[nTableCount - 1]->GetRealCols(aTableVec[nTableCount - 1]->GetColumn()) > nSpannedCols - 1)
506 if ( aTableVec[nTableCount - 1]->GetRow() == 0)
508 InsertColumn();
509 for (sal_Int16 i = sal::static_int_cast<sal_Int16>(nTableCount - 1); i > 0; i--)
511 sal_Int32 nColPos = aTableVec[i - 1]->GetColumn() +
512 aTableVec[i]->GetSpannedCols() - 1;
513 aTableVec[i - 1]->SetColsPerCol(nColPos,
514 aTableVec[i - 1]->GetColsPerCol(nColPos) +
515 aTableVec[nTableCount - 1]->GetColsPerCol(aTableVec[nTableCount - 1]->GetColumn()));
516 aTableVec[i - 1]->SetRealCols(nColPos + 1,
517 aTableVec[i - 1]->GetRealCols(nColPos)
518 + aTableVec[i - 1]->GetColsPerCol(nColPos));
519 aTableVec[i - 1]->SetChangedCols(nColPos);
526 void ScMyTables::AddColumn(sal_Bool bIsCovered)
528 aTableVec[nTableCount - 1]->AddColumn();
529 if (aTableVec[nTableCount - 1]->GetSubTableSpanned() > 1)
530 aTableVec[nTableCount - 1]->SetSubTableSpanned(aTableVec[nTableCount - 1]->GetSubTableSpanned() - 1);
531 else
533 NewColumn(bIsCovered);
534 // if (!bIsCovered)
535 aTableVec[nTableCount - 1]->SetRealCols(aTableVec[nTableCount - 1]->GetColumn() + 1,
536 aTableVec[nTableCount - 1]->GetRealCols(aTableVec[nTableCount - 1]->GetColumn())
537 + aTableVec[nTableCount - 1]->GetColsPerCol(aTableVec[nTableCount - 1]->GetColumn()));
538 if ((!bIsCovered) || (bIsCovered &&
539 (aTableVec[nTableCount - 1]->GetColsPerCol(aTableVec[nTableCount - 1]->GetColumn()) > 1)))
541 if ((aTableVec[nTableCount - 1]->GetRowsPerRow(aTableVec[nTableCount - 1]->GetRow()) > 1) ||
542 (aTableVec[nTableCount - 1]->GetColsPerCol(aTableVec[nTableCount - 1]->GetColumn()) > 1))
543 DoMerge();
548 void ScMyTables::NewTable(sal_Int32 nTempSpannedCols)
550 ++nTableCount;
551 if (static_cast<sal_uInt32>(nTableCount) >= aTableVec.size())
552 aTableVec.resize(aTableVec.size() + nDefaultTabCount);
553 ScMyTableData* aTable(new ScMyTableData(nCurrentSheet));
554 if (nTableCount > 1)
556 ScMyTableData* pTableData = aTableVec[nTableCount - 2];
557 const sal_Int32 nCol(pTableData->GetColumn());
558 const sal_Int32 nColCount(pTableData->GetColCount());
559 const sal_Int32 nColsPerCol(pTableData->GetColsPerCol(nCol));
560 sal_Int32 nSpannedCols(pTableData->GetSpannedCols());
561 sal_Int32 nTemp(nSpannedCols - nColCount);
562 sal_Int32 nTemp2(nCol - (nColCount - 1));
563 if ((nTemp > 0) && (nTemp2 == 0))
564 nTempSpannedCols *= (nTemp + 1);
565 else
566 if (nColsPerCol > 1)
567 nTempSpannedCols *= nColsPerCol;
569 sal_Int32 nToMerge;
570 if (nSpannedCols > nColCount)
571 nToMerge = pTableData->GetChangedCols(nCol, nCol + nColsPerCol + nSpannedCols - nColCount);
572 else
573 nToMerge = pTableData->GetChangedCols(nCol, nCol + nColsPerCol);
574 if (nToMerge > nCol)
575 nTempSpannedCols += nToMerge;
577 aTable->SetSpannedCols(nTempSpannedCols);
578 aTableVec[nTableCount - 1] = aTable;
579 if (nTableCount > 1)
581 aTableVec[nTableCount - 2]->SetSubTableSpanned(aTable->GetSpannedCols());
582 UnMerge();
586 void ScMyTables::UpdateRowHeights()
588 if (rImport.GetModel().is())
590 rImport.LockSolarMutex();
591 // update automatic row heights
592 ScModelObj::getImplementation(rImport.GetModel())->UpdateAllRowHeights();
593 rImport.UnlockSolarMutex();
597 void ScMyTables::DeleteTable()
599 rImport.LockSolarMutex();
601 nCurrentColStylePos = 0;
602 if (nTableCount > 0)
604 ScMyTableData* aTable = aTableVec[nTableCount - 1];
605 delete aTable;
606 aTableVec[nTableCount - 1] = NULL;
607 nTableCount--;
609 if (nTableCount == 0) // only set the styles if all subtables are importet and the table is finished
611 rImport.GetStylesImportHelper()->SetStylesToRanges();
612 rImport.SetStylesToRangesFinished();
615 //#i48793#; has to be set before protection
616 if (!aMatrixRangeList.empty())
618 ScMyMatrixRangeList::iterator aItr = aMatrixRangeList.begin();
619 ScMyMatrixRangeList::iterator aEndItr = aMatrixRangeList.end();
620 while(aItr != aEndItr)
622 SetMatrix(aItr->aRange, aItr->sFormula, aItr->eGrammar);
623 ++aItr;
625 aMatrixRangeList.clear();
628 if (rImport.GetDocument() && maProtectionData.mbProtected)
630 uno::Sequence<sal_Int8> aHash;
631 SvXMLUnitConverter::decodeBase64(aHash, maProtectionData.maPassword);
633 auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
634 pProtect->setProtected(maProtectionData.mbProtected);
635 pProtect->setPasswordHash(aHash, maProtectionData.meHash1, maProtectionData.meHash2);
636 pProtect->setOption(ScTableProtection::SELECT_LOCKED_CELLS, maProtectionData.mbSelectProtectedCells);
637 pProtect->setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, maProtectionData.mbSelectUnprotectedCells);
638 rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), pProtect.get());
641 rImport.UnlockSolarMutex();
643 //#95582#; find out whether it was possible to set the sheet name
644 // test it here, because if it is a linked table the name is changed by importing
645 // the linking informations
646 uno::Reference < container::XNamed > xNamed(xCurrentSheet, uno::UNO_QUERY );
647 if ( xNamed.is() )
649 rtl::OUString sCurrentName(xNamed->getName());
650 if (sCurrentName != sCurrentSheetName && rImport.GetDocument())
652 rImport.GetDocument()->RenameTab( static_cast<SCTAB>(nCurrentSheet),
653 sCurrentSheetName, sal_False, sal_True);
655 /* rtl::OUString sErrorMessage(RTL_CONSTASCII_USTRINGPARAM("Could not create a table with the name "));
656 sErrorMessage += sCurrentSheetName;
657 sErrorMessage += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(". The new name is "));
658 sErrorMessage += sCurrentName;
659 uno::Sequence<rtl::OUString> aSeq(1);
660 aSeq[0] = sErrorMessage;
661 uno::Reference<xml::sax::XLocator> xLocator;
662 rImport.SetError(XMLERROR_API | XMLERROR_FLAG_ERROR, aSeq, rtl::OUString(), xLocator);*/
667 table::CellAddress ScMyTables::GetRealCellPos()
669 sal_Int32 nRow(0);
670 sal_Int32 nCol(0);
671 for (sal_Int32 i = 0; i < nTableCount; ++i)
673 ScMyTableData* pTableData = aTableVec[i];
674 nCol += pTableData->GetRealCols(pTableData->GetColumn());
675 nRow += pTableData->GetRealRows(pTableData->GetRow());
677 aRealCellPos.Row = nRow;
678 aRealCellPos.Column = nCol;
679 aRealCellPos.Sheet = sal::static_int_cast<sal_Int16>(nCurrentSheet);
680 return aRealCellPos;
683 void ScMyTables::AddColCount(sal_Int32 nTempColCount)
685 aTableVec[nTableCount - 1]->SetColCount(aTableVec[nTableCount - 1]->GetColCount() + nTempColCount);
688 void ScMyTables::AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName)
690 DBG_ASSERT(nTableCount == 1, "not possible to use default styles on columns in subtables");
691 rImport.GetStylesImportHelper()->AddColumnStyle(rCellStyleName, nCurrentColStylePos, nRepeat);
692 nCurrentColStylePos += nRepeat;
695 uno::Reference< drawing::XDrawPage > ScMyTables::GetCurrentXDrawPage()
697 if( (nCurrentSheet != nCurrentDrawPage) || !xDrawPage.is() )
699 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier( xCurrentSheet, uno::UNO_QUERY );
700 if( xDrawPageSupplier.is() )
701 xDrawPage.set(xDrawPageSupplier->getDrawPage());
702 nCurrentDrawPage = sal::static_int_cast<sal_Int16>(nCurrentSheet);
704 return xDrawPage;
707 uno::Reference< drawing::XShapes > ScMyTables::GetCurrentXShapes()
709 if( (nCurrentSheet != nCurrentXShapes) || !xShapes.is() )
711 xShapes.set(GetCurrentXDrawPage(), uno::UNO_QUERY);
712 rImport.GetShapeImport()->startPage(xShapes);
713 rImport.GetShapeImport()->pushGroupForSorting ( xShapes );
714 nCurrentXShapes = sal::static_int_cast<sal_Int16>(nCurrentSheet);
715 return xShapes;
717 else
718 return xShapes;
721 sal_Bool ScMyTables::HasDrawPage()
723 return !((nCurrentSheet != nCurrentDrawPage) || !xDrawPage.is());
726 sal_Bool ScMyTables::HasXShapes()
728 return !((nCurrentSheet != nCurrentXShapes) || !xShapes.is());
731 void ScMyTables::AddShape(uno::Reference <drawing::XShape>& rShape,
732 rtl::OUString* pRangeList,
733 table::CellAddress& rStartAddress, table::CellAddress& rEndAddress,
734 sal_Int32 nEndX, sal_Int32 nEndY)
736 aResizeShapes.AddShape(rShape, pRangeList, rStartAddress, rEndAddress, nEndX, nEndY);
739 void ScMyTables::AddMatrixRange(sal_Int32 nStartColumn, sal_Int32 nStartRow, sal_Int32 nEndColumn, sal_Int32 nEndRow, const rtl::OUString& rFormula, const formula::FormulaGrammar::Grammar eGrammar)
741 DBG_ASSERT(nEndRow >= nStartRow, "wrong row order");
742 DBG_ASSERT(nEndColumn >= nStartColumn, "wrong column order");
743 table::CellRangeAddress aRange;
744 aRange.StartColumn = nStartColumn;
745 aRange.StartRow = nStartRow;
746 aRange.EndColumn = nEndColumn;
747 aRange.EndRow = nEndRow;
748 aRange.Sheet = sal::static_int_cast<sal_Int16>(nCurrentSheet);
749 ScMatrixRange aMRange(aRange, rFormula, eGrammar);
750 aMatrixRangeList.push_back(aMRange);
753 sal_Bool ScMyTables::IsPartOfMatrix(sal_Int32 nColumn, sal_Int32 nRow)
755 sal_Bool bResult(sal_False);
756 if (!aMatrixRangeList.empty())
758 ScMyMatrixRangeList::iterator aItr(aMatrixRangeList.begin());
759 ScMyMatrixRangeList::iterator aEndItr(aMatrixRangeList.end());
760 sal_Bool bReady(sal_False);
761 while(!bReady && aItr != aEndItr)
763 if (nCurrentSheet > aItr->aRange.Sheet)
765 DBG_ERROR("should never hapen, because the list should be cleared in DeleteTable");
766 aItr = aMatrixRangeList.erase(aItr);
768 else if ((nRow > aItr->aRange.EndRow) && (nColumn > aItr->aRange.EndColumn))
770 SetMatrix(aItr->aRange, aItr->sFormula, aItr->eGrammar);
771 aItr = aMatrixRangeList.erase(aItr);
773 else if (nColumn < aItr->aRange.StartColumn)
774 bReady = sal_True;
775 else if (nColumn >= aItr->aRange.StartColumn && nColumn <= aItr->aRange.EndColumn && nRow >= aItr->aRange.StartRow && nRow <= aItr->aRange.EndRow)
777 bReady = sal_True;
778 bResult = sal_True;
780 else
781 ++aItr;
784 return bResult;
787 void ScMyTables::SetMatrix(const table::CellRangeAddress& rRange, const rtl::OUString& rFormula, const formula::FormulaGrammar::Grammar eGrammar)
789 uno::Reference <table::XCellRange> xMatrixCellRange(
790 GetCurrentXCellRange()->getCellRangeByPosition(rRange.StartColumn, rRange.StartRow,
791 rRange.EndColumn, rRange.EndRow));
792 if (xMatrixCellRange.is())
794 uno::Reference <sheet::XArrayFormulaRange> xArrayFormulaRange(xMatrixCellRange, uno::UNO_QUERY);
795 if (xArrayFormulaRange.is())
797 ScCellRangeObj* pCellRangeObj =
798 static_cast<ScCellRangeObj*>(ScCellRangesBase::getImplementation(
799 xMatrixCellRange));
800 if (pCellRangeObj)
801 pCellRangeObj->SetArrayFormulaWithGrammar( rFormula, eGrammar);