LibreOffice Module sc (master) 1
xmlsubti.cxx
Go to the documentation of this file.
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#include "xmlsubti.hxx"
21#include "xmlstyli.hxx"
22#include "xmlimprt.hxx"
23#include <document.hxx>
24#include "XMLConverter.hxx"
25#include <docuno.hxx>
27#include <sheetdata.hxx>
28#include <tabprotection.hxx>
29#include <tokenarray.hxx>
30#include <documentimport.hxx>
31
32#include <sal/log.hxx>
33#include <osl/diagnose.h>
34
35#include <comphelper/base64.hxx>
37#include <com/sun/star/sheet/XSpreadsheet.hpp>
38#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
39#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
40
41using namespace com::sun::star;
42
44 meHash1(PASSHASH_SHA1),
45 meHash2(PASSHASH_UNSPECIFIED),
46 mbProtected(false),
47 mbSelectProtectedCells(true),
48 mbSelectUnprotectedCells(true),
49 mbInsertColumns(false),
50 mbInsertRows(false),
51 mbDeleteColumns(false),
52 mbDeleteRows(false)
53{
54}
55
57 : rImport(rTempImport),
58 aFixupOLEs(rTempImport),
59 maCurrentCellPos(ScAddress::INITIALIZE_INVALID),
60 nCurrentColCount(0),
61 nCurrentDrawPage( -1 ),
62 nCurrentXShapes( -1 )
63{
64}
65
67{
68}
69
70namespace {
71
72uno::Reference<sheet::XSpreadsheet> getCurrentSheet(const uno::Reference<frame::XModel>& xModel, SCTAB nSheet)
73{
74 uno::Reference<sheet::XSpreadsheet> xSheet;
75 uno::Reference<sheet::XSpreadsheetDocument> xSpreadDoc(xModel, uno::UNO_QUERY);
76 if (!xSpreadDoc.is())
77 return xSheet;
78
79 uno::Reference <sheet::XSpreadsheets> xSheets(xSpreadDoc->getSheets());
80 if (!xSheets.is())
81 return xSheet;
82
83 uno::Reference <container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY);
84 if (!xIndex.is())
85 return xSheet;
86
87 xSheet.set(xIndex->getByIndex(nSheet), uno::UNO_QUERY);
88 return xSheet;
89}
90
91}
92
93void ScMyTables::NewSheet(const OUString& sTableName, const OUString& sStyleName,
94 const ScXMLTabProtectionData& rProtectData)
95{
96 if (!rImport.GetModel().is())
97 return;
98
100 sCurrentSheetName = sTableName;
101 //reset cols and rows for new sheet, but increment tab
105
106 maProtectionData = rProtectData;
108
109 // The document contains one sheet when created. So for the first
110 // sheet, we only need to set its name.
111 if (maCurrentCellPos.Tab() > 0)
112 pDoc->AppendTabOnLoad(sTableName);
113 else
114 pDoc->SetTabNameOnLoad(maCurrentCellPos.Tab(), sTableName);
115
116 xCurrentSheet = getCurrentSheet(rImport.GetModel(), maCurrentCellPos.Tab());
117 if (xCurrentSheet.is())
118 {
119 // We need to set the current cell range here regardless of
120 // presence of style name.
121 SetTableStyle(sStyleName);
122 }
123}
124
125void ScMyTables::SetTableStyle(const OUString& sStyleName)
126{
127 //these uno calls are a bit difficult to remove, XMLTableStyleContext::FillPropertySet uses
128 //SvXMLImportPropertyMapper::FillPropertySet
129 if ( sStyleName.isEmpty() )
130 return;
131
132 // #i57869# All table style properties for all sheets are now applied here,
133 // before importing the contents.
134 // This is needed for the background color.
135 // Sheet visibility has special handling in ScDocFunc::SetTableVisible to
136 // allow hiding the first sheet.
137 // RTL layout is only remembered, not actually applied, so the shapes can
138 // be loaded before mirroring.
139
140 if ( !xCurrentSheet.is() )
141 return;
142
143 uno::Reference <beans::XPropertySet> xProperties(xCurrentSheet, uno::UNO_QUERY);
144 if ( !xProperties.is() )
145 return;
146
147 XMLTableStylesContext *pStyles = static_cast<XMLTableStylesContext *>(rImport.GetAutoStyles());
148 if ( pStyles )
149 {
150 XMLTableStyleContext* pStyle = const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
151 XmlStyleFamily::TABLE_TABLE, sStyleName, true)));
152 if ( pStyle )
153 {
154 pStyle->FillPropertySet(xProperties);
155
156 ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(rImport.GetModel())->GetSheetSaveData();
157 pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, maCurrentCellPos.Tab() ) );
158 }
159 }
160}
161
163{
165 maCurrentCellPos.SetCol(-1); //reset columns for new row
166}
167
168void ScMyTables::SetRowStyle(const OUString& rCellStyleName)
169{
170 rImport.GetStylesImportHelper()->SetRowStyle(rCellStyleName);
171}
172
173void ScMyTables::AddColumn(bool bIsCovered)
174{
176 //here only need to set column style if this is the first row and
177 //the cell is not covered.
178 if(maCurrentCellPos.Row() == 0 && !bIsCovered)
180}
181
183{
185
188
190
192 return;
193
194 uno::Sequence<sal_Int8> aHash;
196
197 ScTableProtection aProtect;
207}
208
209void ScMyTables::AddColStyle(const sal_Int32 nRepeat, const OUString& rCellStyleName)
210{
212 nCurrentColCount += nRepeat;
214 "sc", "more columns than fit into SCCOL");
216}
217
218uno::Reference< drawing::XDrawPage > const & ScMyTables::GetCurrentXDrawPage()
219{
220 if( (maCurrentCellPos.Tab() != nCurrentDrawPage) || !xDrawPage.is() )
221 {
222 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier( xCurrentSheet, uno::UNO_QUERY );
223 if( xDrawPageSupplier.is() )
224 xDrawPage.set(xDrawPageSupplier->getDrawPage());
225 nCurrentDrawPage = sal::static_int_cast<sal_Int16>(maCurrentCellPos.Tab());
226 }
227 return xDrawPage;
228}
229
230uno::Reference< drawing::XShapes > const & ScMyTables::GetCurrentXShapes()
231{
232 if( (maCurrentCellPos.Tab() != nCurrentXShapes) || !xShapes.is() )
233 {
235 rImport.GetShapeImport()->startPage(xShapes);
236 rImport.GetShapeImport()->pushGroupForPostProcessing ( xShapes );
237 nCurrentXShapes = sal::static_int_cast<sal_Int16>(maCurrentCellPos.Tab());
238 }
239 return xShapes;
240}
241
243{
244 return (maCurrentCellPos.Tab() == nCurrentDrawPage) && xDrawPage.is();
245}
246
248{
249 return (maCurrentCellPos.Tab() == nCurrentXShapes) && xShapes.is();
250}
251
252void ScMyTables::AddOLE(const uno::Reference <drawing::XShape>& rShape,
253 const OUString &rRangeList)
254{
255 aFixupOLEs.AddOLE(rShape, rRangeList);
256}
257
259 const SCCOL nStartColumn, const SCROW nStartRow, const SCCOL nEndColumn, const SCROW nEndRow,
260 const OUString& rFormula, const OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar)
261{
262 OSL_ENSURE(nEndRow >= nStartRow, "wrong row order");
263 OSL_ENSURE(nEndColumn >= nStartColumn, "wrong column order");
264 ScRange aScRange(
265 nStartColumn, nStartRow, maCurrentCellPos.Tab(),
266 nEndColumn, nEndRow, maCurrentCellPos.Tab()
267 );
268
270
272 ScTokenArray aCode(rDoc.getDoc());
273 aCode.AssignXMLString( rFormula,
274 ((eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) ? rFormulaNmsp : OUString()));
275 rDoc.setMatrixCells(aScRange, aCode, eGrammar);
276 rDoc.getDoc().IncXMLImportedFormulaCount( rFormula.getLength() );
277}
278
279bool ScMyTables::IsPartOfMatrix(const ScAddress& rScAddress) const
280{
282 return maMatrixRangeList.Contains(rScAddress);
283 return false;
284}
285
287{
288 return std::min<sal_Int32>(nCurrentColCount, rImport.GetDocument()->MaxCol());
289}
290
291/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB Tab() const
Definition: address.hxx:283
void SetCol(SCCOL nColP)
Definition: address.hxx:291
SCROW Row() const
Definition: address.hxx:274
void SetRow(SCROW nRowP)
Definition: address.hxx:287
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SCCOL Col() const
Definition: address.hxx:279
Accessor class to ScDocument.
void setMatrixCells(const ScRange &rRange, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGrammar)
ScDocument & getDoc()
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:898
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
void AppendTabOnLoad(const OUString &rName)
Definition: document.cxx:453
void SetTabNameOnLoad(SCTAB nTab, const OUString &rName)
Definition: document.cxx:465
SC_DLLPUBLIC void SetTabProtection(SCTAB nTab, const ScTableProtection *pProtect)
Definition: documen3.cxx:1922
void IncXMLImportedFormulaCount(sal_uInt64 nVal)
Definition: document.hxx:2460
void AddOLE(const css::uno::Reference< css::drawing::XShape > &rShape, const OUString &rRangeList)
void AddColumnStyle(const OUString &rStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat)
void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab)
void SetRowStyle(const OUString &rStyleName)
void AddColumn(bool bIsCovered)
Definition: xmlsubti.cxx:173
sal_Int16 nCurrentDrawPage
Definition: xmlsubti.hxx:64
css::uno::Reference< css::sheet::XSpreadsheet > xCurrentSheet
Definition: xmlsubti.hxx:56
sal_Int16 nCurrentXShapes
Definition: xmlsubti.hxx:65
ScXMLImport & rImport
Definition: xmlsubti.hxx:52
ScRangeList maMatrixRangeList
Definition: xmlsubti.hxx:61
void AddRow()
Definition: xmlsubti.cxx:162
css::uno::Reference< css::drawing::XShapes > const & GetCurrentXShapes()
Definition: xmlsubti.cxx:230
css::uno::Reference< css::drawing::XDrawPage > xDrawPage
Definition: xmlsubti.hxx:57
void SetRowStyle(const OUString &rCellStyleName)
Definition: xmlsubti.cxx:168
OUString sCurrentSheetName
Definition: xmlsubti.hxx:59
sal_Int32 nCurrentColCount
Definition: xmlsubti.hxx:63
void AddOLE(const css::uno::Reference< css::drawing::XShape > &rShape, const OUString &rRangeList)
Definition: xmlsubti.cxx:252
void NewSheet(const OUString &sTableName, const OUString &sStyleName, const ScXMLTabProtectionData &rProtectData)
Definition: xmlsubti.cxx:93
bool IsPartOfMatrix(const ScAddress &rScAddress) const
Definition: xmlsubti.cxx:279
ScXMLTabProtectionData maProtectionData
Definition: xmlsubti.hxx:62
SCCOL GetCurrentColCount() const
Definition: xmlsubti.cxx:286
ScMyOLEFixer aFixupOLEs
Definition: xmlsubti.hxx:54
css::uno::Reference< css::drawing::XDrawPage > const & GetCurrentXDrawPage()
Definition: xmlsubti.cxx:218
void DeleteTable()
Definition: xmlsubti.cxx:182
ScAddress maCurrentCellPos
Definition: xmlsubti.hxx:60
void AddMatrixRange(const SCCOL nStartColumn, const SCROW nStartRow, const SCCOL nEndColumn, const SCROW nEndRow, const OUString &rFormula, const OUString &rFormulaNmsp, const formula::FormulaGrammar::Grammar)
Definition: xmlsubti.cxx:258
css::uno::Reference< css::drawing::XShapes > xShapes
Definition: xmlsubti.hxx:58
bool HasDrawPage() const
Definition: xmlsubti.cxx:242
void AddColStyle(const sal_Int32 nRepeat, const OUString &rCellStyleName)
Definition: xmlsubti.cxx:209
void SetTableStyle(const OUString &sStyleName)
Definition: xmlsubti.cxx:125
ScMyTables(ScXMLImport &rImport)
Definition: xmlsubti.cxx:56
bool HasXShapes() const
Definition: xmlsubti.cxx:247
void RemoveAll()
Definition: rangelst.cxx:1101
bool Contains(const ScRange &) const
Definition: rangelst.cxx:1082
bool empty() const
Definition: rangelst.hxx:88
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1137
void AddTableStyle(const OUString &rName, const ScAddress &rCellPos)
Definition: sheetdata.cxx:56
sheet protection state container
void setOption(Option eOption, bool bEnabled)
virtual void setPasswordHash(const css::uno::Sequence< sal_Int8 > &aPassword, ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) override
virtual void setProtected(bool bProtected) override
void AssignXMLString(const OUString &rText, const OUString &rFormulaNmsp)
Assign XML string placeholder to the array.
Definition: token.cxx:2324
static ScDocument * GetScDocument(const css::uno::Reference< css::frame::XModel > &xModel)
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:289
ScMyStylesImportHelper * GetStylesImportHelper()
Definition: xmlimprt.hxx:250
ScDocumentImport & GetDoc()
Definition: xmlimprt.cxx:506
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
void SetStylesToRangesFinished()
Definition: xmlimprt.cxx:1111
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
Definition: xmlstyli.cxx:519
static void decode(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
#define SAL_WARN_IF(condition, area, stream)
SCCOL GetMaxColCount() const
Definition: sheetlimits.hxx:68
ScPasswordHash meHash1
Definition: xmlsubti.hxx:36
ScPasswordHash meHash2
Definition: xmlsubti.hxx:37
@ PASSHASH_UNSPECIFIED
@ PASSHASH_SHA1
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17