1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
38 #include "xmlstyli.hxx"
39 #include "xmlimprt.hxx"
40 #include "document.hxx"
41 #include "XMLConverter.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>
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),
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
)
83 for (sal_Int32 j
= 0; j
< 3; ++j
)
91 ScMyTableData::~ScMyTableData()
95 void ScMyTableData::AddRow()
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
)))
131 if ((*i
>= nFromIndex
) && (*i
< nToIndex
))
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
))
145 if ((i
== endi
) || (*i
!= nValue
))
146 nChangedCols
.insert(i
, nValue
);
149 /*******************************************************************************************************************************/
151 ScXMLTabProtectionData::ScXMLTabProtectionData() :
152 meHash1(PASSHASH_UNSPECIFIED
),
153 meHash2(PASSHASH_UNSPECIFIED
),
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 ),
169 aTableVec
.resize(nDefaultTabCount
, NULL
);
172 ScMyTables::~ScMyTables()
174 ScMyTableData
* pTable
;
175 while (nTableCount
> 0)
177 pTable
= aTableVec
[nTableCount
- 1];
179 aTableVec
[nTableCount
- 1] = NULL
;
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];
196 aTableVec
[nTableCount
- 1] = NULL
;
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());
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());
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
);
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
);
241 xNamed
->setName(sTableName
);
243 catch ( uno::RuntimeException
& )
245 ScDocument
*pDoc
= ScXMLConverter::GetScDocument(rImport
.GetModel());
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();
275 XMLTableStyleContext
* pStyle
= (XMLTableStyleContext
*)pStyles
->FindStyleChildContext(
276 XML_STYLE_FAMILY_TABLE_TABLE
, sStyleName
, sal_True
);
278 pStyle
->FillPropertySet(xProperties
);
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
);
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
)
319 void ScMyTables::UnMerge()
321 if ( xCurrentCellRange
.is() )
323 table::CellRangeAddress aCellAddress
;
324 if (IsMerged(xCurrentCellRange
, GetRealCellPos().Column
, GetRealCellPos().Row
, aCellAddress
))
327 uno::Reference
<util::XMergeable
> xMergeable (xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
328 aCellAddress
.EndColumn
, aCellAddress
.EndRow
), uno::UNO_QUERY
);
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
))
343 uno::Reference
<util::XMergeable
> xMergeable (xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
344 aCellAddress
.EndColumn
, aCellAddress
.EndRow
), uno::UNO_QUERY
);
346 xMergeable
->merge(sal_False
);
350 uno::Reference
<table::XCellRange
> xMergeCellRange
;
352 xMergeCellRange
.set(xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
353 aCellAddress
.EndColumn
354 + aTableVec
[nTableCount
- 1]->GetColsPerCol(aTableVec
[nTableCount
- 1]->GetColumn()) - 1,
356 + aTableVec
[nTableCount
- 1]->GetRowsPerRow(aTableVec
[nTableCount
- 1]->GetRow()) - 1));
358 xMergeCellRange
.set(xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
359 aCellAddress
.StartColumn
361 aCellAddress
.EndRow
));
362 uno::Reference
<util::XMergeable
> xMergeable (xMergeCellRange
, uno::UNO_QUERY
);
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
))
379 uno::Reference
<util::XMergeable
> xMergeable (xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
380 aCellAddress
.EndColumn
, aCellAddress
.EndRow
), uno::UNO_QUERY
);
382 xMergeable
->merge(sal_False
);
386 uno::Reference
<util::XMergeable
> xMergeable (xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
387 aCellAddress
.EndColumn
, aCellAddress
.EndRow
+ 1), uno::UNO_QUERY
);
389 xMergeable
->merge(sal_True
);
390 j
+= aCellAddress
.EndColumn
- aCellAddress
.StartColumn
;
392 rImport
.GetStylesImportHelper()->InsertRow(nRow
, nCurrentSheet
, rImport
.GetDocument());
396 void ScMyTables::NewRow()
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)
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();
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
))
445 uno::Reference
<util::XMergeable
> xMergeable (xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
446 aCellAddress
.EndColumn
, aCellAddress
.EndRow
), uno::UNO_QUERY
);
448 xMergeable
->merge(sal_False
);
449 aTempCellAddress
= aCellAddress
;
450 aTempCellAddress
.StartColumn
= aTempCellAddress
.EndColumn
+ 1;
451 aTempCellAddress
.EndColumn
= aTempCellAddress
.StartColumn
;
455 aTempCellAddress
= aCellAddress
;
456 aTempCellAddress
.StartColumn
+= 1;
457 aTempCellAddress
.EndColumn
= aTempCellAddress
.StartColumn
;
461 sheet::CellInsertMode
aCellInsertMode(sheet::CellInsertMode_RIGHT
);
462 uno::Reference
<sheet::XCellRangeMovement
> xCellRangeMovement (xCurrentSheet
, uno::UNO_QUERY
);
463 xCellRangeMovement
->insertCells(aTempCellAddress
, aCellInsertMode
);
466 uno::Reference
<util::XMergeable
> xMergeable (xCurrentCellRange
->getCellRangeByPosition(aCellAddress
.StartColumn
, aCellAddress
.StartRow
,
467 aCellAddress
.EndColumn
+ 1, aCellAddress
.EndRow
), uno::UNO_QUERY
);
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
)
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) )
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
)
498 aTableVec
[nTableCount
- 1]->SetColsPerCol(nColCount
- 1, LastColSpanned
);
499 aTableVec
[nTableCount
- 1]->SetRealCols(nColCount
- 1 + 1,
500 aTableVec
[nTableCount
- 1]->GetRealCols(nColCount
- 1)
504 if (aTableVec
[nTableCount
- 1]->GetRealCols(aTableVec
[nTableCount
- 1]->GetColumn()) > nSpannedCols
- 1)
506 if ( aTableVec
[nTableCount
- 1]->GetRow() == 0)
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);
533 NewColumn(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))
548 void ScMyTables::NewTable(sal_Int32 nTempSpannedCols
)
551 if (static_cast<sal_uInt32
>(nTableCount
) >= aTableVec
.size())
552 aTableVec
.resize(aTableVec
.size() + nDefaultTabCount
);
553 ScMyTableData
* aTable(new ScMyTableData(nCurrentSheet
));
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);
567 nTempSpannedCols
*= nColsPerCol
;
570 if (nSpannedCols
> nColCount
)
571 nToMerge
= pTableData
->GetChangedCols(nCol
, nCol
+ nColsPerCol
+ nSpannedCols
- nColCount
);
573 nToMerge
= pTableData
->GetChangedCols(nCol
, nCol
+ nColsPerCol
);
575 nTempSpannedCols
+= nToMerge
;
577 aTable
->SetSpannedCols(nTempSpannedCols
);
578 aTableVec
[nTableCount
- 1] = aTable
;
581 aTableVec
[nTableCount
- 2]->SetSubTableSpanned(aTable
->GetSpannedCols());
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;
604 ScMyTableData
* aTable
= aTableVec
[nTableCount
- 1];
606 aTableVec
[nTableCount
- 1] = NULL
;
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
);
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
);
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()
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
);
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
);
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
);
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
)
775 else if (nColumn
>= aItr
->aRange
.StartColumn
&& nColumn
<= aItr
->aRange
.EndColumn
&& nRow
>= aItr
->aRange
.StartRow
&& nRow
<= aItr
->aRange
.EndRow
)
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(
801 pCellRangeObj
->SetArrayFormulaWithGrammar( rFormula
, eGrammar
);