tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / filter / xml / xmldrani.cxx
blob8a91e8d44959d30bfc4639b1521d8618370d13b2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmldrani.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlfilti.hxx"
23 #include "xmlsorti.hxx"
24 #include <document.hxx>
25 #include <globalnames.hxx>
26 #include <dbdata.hxx>
27 #include <datauno.hxx>
28 #include <attrib.hxx>
29 #include <unonames.hxx>
30 #include "XMLConverter.hxx"
31 #include <rangeutl.hxx>
32 #include <dputil.hxx>
33 #include <sortparam.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmlnamespace.hxx>
38 #include <sax/tools/converter.hxx>
40 #include <com/sun/star/sheet/DataImportMode.hpp>
41 #include <com/sun/star/table/TableOrientation.hpp>
42 #include <osl/diagnose.h>
43 #include <o3tl/string_view.hxx>
45 #include <memory>
47 using namespace com::sun::star;
48 using namespace xmloff::token;
50 ScXMLDatabaseRangesContext::ScXMLDatabaseRangesContext( ScXMLImport& rImport ) :
51 ScXMLImportContext( rImport )
53 // has no attributes
54 rImport.LockSolarMutex();
57 ScXMLDatabaseRangesContext::~ScXMLDatabaseRangesContext()
59 GetScImport().UnlockSolarMutex();
62 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDatabaseRangesContext::createFastChildContext(
63 sal_Int32 nElement,
64 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
66 SvXMLImportContext *pContext = nullptr;
67 sax_fastparser::FastAttributeList *pAttribList =
68 &sax_fastparser::castToFastAttributeList( xAttrList );
70 switch( nElement )
72 case XML_ELEMENT( TABLE, XML_DATABASE_RANGE ):
74 pContext = new ScXMLDatabaseRangeContext( GetScImport(), pAttribList );
76 break;
79 return pContext;
82 ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( ScXMLImport& rImport,
83 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
84 ScXMLImportContext( rImport ),
85 mpQueryParam(new ScQueryParam),
86 sDatabaseRangeName(STR_DB_LOCAL_NONAME),
87 nSourceType(sheet::DataImportMode_NONE),
88 nRefresh(0),
89 nSubTotalsUserListIndex(0),
90 mbValidRange(true),
91 bContainsSort(false),
92 bContainsSubTotal(false),
93 bNative(true),
94 bIsSelection(false),
95 bKeepFormats(false),
96 bMoveCells(false),
97 bStripData(false),
98 bAutoFilter(false),
99 bSubTotalsBindFormatsToContent(false),
100 bSubTotalsIsCaseSensitive(false),
101 bSubTotalsInsertPageBreaks(false),
102 bSubTotalsSummaryBelow(true),
103 bSubTotalsSortGroups(false),
104 bSubTotalsEnabledUserList(false),
105 bSubTotalsAscending(true),
106 bFilterConditionSourceRange(false),
107 bHasHeader(true),
108 bHasFooter(false),
109 bByRow(true),
110 meRangeType(ScDBCollection::GlobalNamed)
112 if( rAttrList.is() )
114 for( auto &aIter : *rAttrList )
116 switch( aIter.getToken() )
118 case XML_ELEMENT( TABLE, XML_NAME ):
120 sDatabaseRangeName = aIter.toString();
122 break;
123 case XML_ELEMENT( TABLE, XML_IS_SELECTION ):
125 bIsSelection = IsXMLToken( aIter, XML_TRUE );
127 break;
128 case XML_ELEMENT( TABLE, XML_ON_UPDATE_KEEP_STYLES ):
130 bKeepFormats = IsXMLToken( aIter, XML_TRUE );
132 break;
133 case XML_ELEMENT( TABLE, XML_ON_UPDATE_KEEP_SIZE ):
135 bMoveCells = !IsXMLToken( aIter, XML_TRUE );
137 break;
138 case XML_ELEMENT( TABLE, XML_HAS_PERSISTENT_DATA ):
140 bStripData = !IsXMLToken( aIter, XML_TRUE );
142 break;
143 case XML_ELEMENT( TABLE, XML_ORIENTATION ):
145 bByRow = !IsXMLToken( aIter, XML_COLUMN );
146 mpQueryParam->bByRow = bByRow;
148 break;
149 case XML_ELEMENT( TABLE, XML_CONTAINS_HEADER ):
151 bHasHeader = IsXMLToken( aIter, XML_TRUE );
152 mpQueryParam->bHasHeader = bHasHeader;
154 break;
155 case XML_ELEMENT( TABLE, XML_CONTAINS_FOOTER ):
156 case XML_ELEMENT( CALC_EXT, XML_CONTAINS_FOOTER ):
158 bHasFooter = IsXMLToken( aIter, XML_TRUE );
159 mpQueryParam->bHasTotals = bHasFooter;
161 break;
162 case XML_ELEMENT( TABLE, XML_DISPLAY_FILTER_BUTTONS ):
164 bAutoFilter = IsXMLToken( aIter, XML_TRUE );
166 break;
167 case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
169 ScDocument* pDoc = GetScImport().GetDocument();
170 assert(pDoc);
171 sal_Int32 nOffset = 0;
172 if (!ScRangeStringConverter::GetRangeFromString(
173 maRange, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset))
174 mbValidRange = false;
176 break;
177 case XML_ELEMENT( TABLE, XML_REFRESH_DELAY ):
179 double fTime;
180 if (::sax::Converter::convertDuration( fTime, aIter.toView() ))
181 nRefresh = std::max( static_cast<sal_Int32>(fTime * 86400.0), sal_Int32(0) );
183 break;
188 mpQueryParam->nTab = maRange.aStart.Tab();
189 mpQueryParam->nCol1 = maRange.aStart.Col();
190 mpQueryParam->nRow1 = maRange.aStart.Row();
191 mpQueryParam->nCol2 = maRange.aEnd.Col();
192 mpQueryParam->nRow2 = maRange.aEnd.Row();
194 if (sDatabaseRangeName.startsWith(STR_DB_LOCAL_NONAME))
195 meRangeType = ScDBCollection::SheetAnonymous;
196 else if (sDatabaseRangeName.startsWith(STR_DB_GLOBAL_NONAME))
197 meRangeType = ScDBCollection::GlobalAnonymous;
200 ScXMLDatabaseRangeContext::~ScXMLDatabaseRangeContext()
204 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDatabaseRangeContext::createFastChildContext(
205 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
207 SvXMLImportContext *pContext = nullptr;
208 sax_fastparser::FastAttributeList *pAttribList =
209 &sax_fastparser::castToFastAttributeList( xAttrList );
211 switch (nElement)
213 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_SQL ):
215 pContext = new ScXMLSourceSQLContext( GetScImport(), pAttribList, this);
217 break;
218 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_TABLE ):
220 pContext = new ScXMLSourceTableContext( GetScImport(), pAttribList, this);
222 break;
223 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_QUERY ):
225 pContext = new ScXMLSourceQueryContext( GetScImport(), pAttribList, this);
227 break;
228 case XML_ELEMENT( TABLE, XML_FILTER ):
230 pContext = new ScXMLFilterContext(
231 GetScImport(), pAttribList, *mpQueryParam, this);
233 break;
234 case XML_ELEMENT( TABLE, XML_SORT ):
236 bContainsSort = true;
237 pContext = new ScXMLSortContext( GetScImport(), pAttribList, this);
239 break;
240 case XML_ELEMENT( TABLE, XML_SUBTOTAL_RULES ):
242 bContainsSubTotal = true;
243 pContext = new ScXMLSubTotalRulesContext( GetScImport(), pAttribList, this);
245 break;
248 return pContext;
251 std::unique_ptr<ScDBData> ScXMLDatabaseRangeContext::ConvertToDBData(const OUString& rName)
253 if (!mbValidRange)
254 return nullptr;
256 ScDocument* pDoc = GetScImport().GetDocument();
258 ::std::unique_ptr<ScDBData> pData(
259 new ScDBData(rName, maRange.aStart.Tab(), maRange.aStart.Col(), maRange.aStart.Row(), maRange.aEnd.Col(), maRange.aEnd.Row(), bByRow, bHasHeader, bHasFooter));
261 pData->SetAutoFilter(bAutoFilter);
262 pData->SetKeepFmt(bKeepFormats);
263 pData->SetDoSize(bMoveCells);
264 pData->SetStripData(bStripData);
266 pDoc->PrepareQuery(mpQueryParam->nTab, *mpQueryParam);
268 pData->SetQueryParam(*mpQueryParam);
270 if (bFilterConditionSourceRange)
272 pData->SetAdvancedQuerySource( &aFilterConditionSourceRangeAddress );
276 ScImportParam aParam;
277 aParam.bNative = bNative;
278 aParam.aDBName = sDatabaseName.isEmpty() ? sConnectionResource : sDatabaseName;
279 aParam.aStatement = sSourceObject;
280 switch (nSourceType)
282 case sheet::DataImportMode_NONE:
283 aParam.bImport = false;
284 break;
285 case sheet::DataImportMode_SQL:
286 aParam.bImport = true;
287 aParam.bSql = true;
288 break;
289 case sheet::DataImportMode_TABLE:
290 aParam.bImport = true;
291 aParam.bSql = false;
292 aParam.nType = ScDbTable;
293 break;
294 case sheet::DataImportMode_QUERY:
295 aParam.bImport = true;
296 aParam.bSql = false;
297 aParam.nType = ScDbQuery;
298 break;
299 default:
300 OSL_FAIL("Unknown data import mode");
301 aParam.bImport = false;
303 pData->SetImportParam(aParam);
306 if (bContainsSort)
308 size_t nOldSize = aSortSequence.getLength();
309 aSortSequence.realloc(nOldSize + 1);
310 beans::PropertyValue aProperty;
311 aProperty.Name = SC_UNONAME_ORIENT;
312 table::TableOrientation eOrient = mpQueryParam->bByRow ?
313 table::TableOrientation_ROWS : table::TableOrientation_COLUMNS;
314 aProperty.Value <<= eOrient;
315 aSortSequence.getArray()[nOldSize] = std::move(aProperty);
316 ScSortParam aParam;
317 ScSortDescriptor::FillSortParam(aParam, aSortSequence);
319 SCCOLROW nStartPos = aParam.bByRow ? maRange.aStart.Col() : maRange.aStart.Row();
320 for (size_t i = 0; i < aParam.GetSortKeyCount(); ++i)
322 if (!aParam.maKeyState[i].bDoSort)
323 break;
324 aParam.maKeyState[i].nField += nStartPos;
327 pData->SetSortParam(aParam);
330 if (bContainsSubTotal)
332 ScSubTotalParam aParam;
333 aParam.bIncludePattern = bSubTotalsBindFormatsToContent;
334 aParam.bUserDef = bSubTotalsEnabledUserList;
335 aParam.nUserIndex = nSubTotalsUserListIndex;
336 aParam.bPagebreak = bSubTotalsInsertPageBreaks;
337 aParam.bSummaryBelow = bSubTotalsSummaryBelow;
338 aParam.bCaseSens = bSubTotalsIsCaseSensitive;
339 aParam.bDoSort = bSubTotalsSortGroups;
340 aParam.bAscending = bSubTotalsAscending;
341 size_t nPos = 0;
342 for (const auto& rSubTotalRule : aSubTotalRules)
344 if (nPos >= MAXSUBTOTAL)
345 break;
346 auto& group = aParam.aGroups[nPos];
348 const uno::Sequence<sheet::SubTotalColumn>& rColumns = rSubTotalRule.aSubTotalColumns;
349 sal_Int16 nGroupColumn = rSubTotalRule.nSubTotalRuleGroupFieldNumber;
350 group.bActive = true;
351 group.nField = static_cast<SCCOL>(nGroupColumn);
353 group.SetSubtotals(rColumns);
354 ++nPos;
357 pData->SetSubTotalParam(aParam);
360 if (pData->HasImportParam() && !pData->HasImportSelection())
362 pData->SetRefreshDelay(nRefresh);
363 pData->SetRefreshHandler(pDoc->GetDBCollection()->GetRefreshHandler());
364 pData->SetRefreshControl(&pDoc->GetRefreshTimerControlAddress());
367 return pData;
370 namespace {
372 bool setAutoFilterFlags(ScDocument& rDoc, const ScDBData& rData)
374 if (!rData.HasAutoFilter())
375 return false;
377 // Set autofilter flags so that the buttons get displayed.
378 ScRange aRange;
379 rData.GetArea(aRange);
380 rDoc.ApplyFlagsTab(
381 aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aStart.Row(),
382 aRange.aStart.Tab(), ScMF::Auto);
383 return false;
388 void SAL_CALL ScXMLDatabaseRangeContext::endFastElement( sal_Int32 /*nElement*/ )
390 ScDocument* pDoc = GetScImport().GetDocument();
391 if (!pDoc)
392 return;
394 if (meRangeType == ScDBCollection::SheetAnonymous)
396 ::std::unique_ptr<ScDBData> pData(ConvertToDBData(STR_DB_LOCAL_NONAME));
398 if (pData)
400 ScRange aRange;
401 pData->GetArea(aRange);
403 setAutoFilterFlags(*pDoc, *pData);
404 pDoc->SetAnonymousDBData(aRange.aStart.Tab(), std::move(pData));
406 return;
408 else if (meRangeType == ScDBCollection::GlobalAnonymous)
410 ::std::unique_ptr<ScDBData> pData(ConvertToDBData(STR_DB_GLOBAL_NONAME));
412 if (pData)
414 ScRange aRange;
415 pData->GetArea(aRange);
417 if (setAutoFilterFlags(*pDoc, *pData))
418 pDoc->SetAnonymousDBData(aRange.aStart.Tab(), std::move(pData));
419 else
420 pDoc->GetDBCollection()->getAnonDBs().insert(pData.release());
422 return;
424 else if (meRangeType == ScDBCollection::GlobalNamed)
426 ::std::unique_ptr<ScDBData> pData(ConvertToDBData(sDatabaseRangeName));
428 if (pData)
430 setAutoFilterFlags(*pDoc, *pData);
431 (void)pDoc->GetDBCollection()->getNamedDBs().insert(std::move(pData));
436 ScXMLSourceSQLContext::ScXMLSourceSQLContext( ScXMLImport& rImport,
437 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
438 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
439 ScXMLImportContext( rImport ),
440 pDatabaseRangeContext(pTempDatabaseRangeContext)
442 if ( rAttrList.is() )
444 for (auto &aIter : *rAttrList)
446 switch (aIter.getToken())
448 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
449 sDBName = aIter.toString();
450 break;
451 case XML_ELEMENT( TABLE, XML_SQL_STATEMENT ):
452 pDatabaseRangeContext->SetSourceObject(aIter.toString());
453 break;
454 case XML_ELEMENT( TABLE, XML_PARSE_SQL_STATEMENT ):
455 pDatabaseRangeContext->SetNative(IsXMLToken(aIter, XML_TRUE));
456 break;
460 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_SQL);
463 ScXMLSourceSQLContext::~ScXMLSourceSQLContext()
467 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSourceSQLContext::createFastChildContext(
468 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
470 SvXMLImportContext *pContext = nullptr;
471 sax_fastparser::FastAttributeList *pAttribList =
472 &sax_fastparser::castToFastAttributeList( xAttrList );
474 if ( nElement == XML_ELEMENT( FORM, XML_CONNECTION_RESOURCE ) && sDBName.isEmpty() )
476 pContext = new ScXMLConResContext( GetScImport(), pAttribList, pDatabaseRangeContext);
479 return pContext;
482 void SAL_CALL ScXMLSourceSQLContext::endFastElement( sal_Int32 /*nElement*/ )
484 if (!sDBName.isEmpty())
485 pDatabaseRangeContext->SetDatabaseName(sDBName);
488 ScXMLSourceTableContext::ScXMLSourceTableContext( ScXMLImport& rImport,
489 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
490 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
491 ScXMLImportContext( rImport ),
492 pDatabaseRangeContext(pTempDatabaseRangeContext)
494 if ( rAttrList.is() )
496 for (auto &aIter : *rAttrList)
498 switch (aIter.getToken())
500 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
501 sDBName = aIter.toString();
502 break;
503 case XML_ELEMENT( TABLE, XML_TABLE_NAME ):
504 case XML_ELEMENT( TABLE, XML_DATABASE_TABLE_NAME ):
505 pDatabaseRangeContext->SetSourceObject(aIter.toString());
506 break;
510 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_TABLE);
513 ScXMLSourceTableContext::~ScXMLSourceTableContext()
517 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSourceTableContext::createFastChildContext(
518 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
520 SvXMLImportContext *pContext = nullptr;
521 sax_fastparser::FastAttributeList *pAttribList =
522 &sax_fastparser::castToFastAttributeList( xAttrList );
524 if ( nElement == XML_ELEMENT( FORM, XML_CONNECTION_RESOURCE ) && sDBName.isEmpty() )
526 pContext = new ScXMLConResContext( GetScImport(), pAttribList, pDatabaseRangeContext);
529 return pContext;
532 void SAL_CALL ScXMLSourceTableContext::endFastElement( sal_Int32 /*nElement*/ )
534 if (!sDBName.isEmpty())
535 pDatabaseRangeContext->SetDatabaseName(sDBName);
538 ScXMLSourceQueryContext::ScXMLSourceQueryContext( ScXMLImport& rImport,
539 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
540 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
541 ScXMLImportContext( rImport ),
542 pDatabaseRangeContext(pTempDatabaseRangeContext)
544 if ( rAttrList.is() )
546 for (auto &aIter : *rAttrList)
548 switch (aIter.getToken())
550 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
551 sDBName = aIter.toString();
552 break;
553 case XML_ELEMENT( TABLE, XML_QUERY_NAME ):
554 pDatabaseRangeContext->SetSourceObject(aIter.toString());
555 break;
559 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_QUERY);
562 ScXMLSourceQueryContext::~ScXMLSourceQueryContext()
566 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSourceQueryContext::createFastChildContext(
567 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
569 SvXMLImportContext *pContext = nullptr;
570 sax_fastparser::FastAttributeList *pAttribList =
571 &sax_fastparser::castToFastAttributeList( xAttrList );
573 if ( nElement == XML_ELEMENT( FORM, XML_CONNECTION_RESOURCE ) && sDBName.isEmpty() )
575 pContext = new ScXMLConResContext( GetScImport(), pAttribList, pDatabaseRangeContext);
578 return pContext;
581 void SAL_CALL ScXMLSourceQueryContext::endFastElement( sal_Int32 /*nElement*/ )
583 if (!sDBName.isEmpty())
584 pDatabaseRangeContext->SetDatabaseName(sDBName);
587 ScXMLConResContext::ScXMLConResContext( ScXMLImport& rImport,
588 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
589 ScXMLDatabaseRangeContext* pDatabaseRangeContext) :
590 ScXMLImportContext( rImport )
592 OUString sConRes;
593 if ( rAttrList.is() )
595 auto aIter( rAttrList->find( XML_ELEMENT( XLINK, XML_HREF ) ) );
596 if (aIter != rAttrList->end())
597 sConRes = aIter.toString();
599 if (!sConRes.isEmpty())
600 pDatabaseRangeContext->SetConnectionResource(sConRes);
603 ScXMLConResContext::~ScXMLConResContext()
607 ScXMLSubTotalRulesContext::ScXMLSubTotalRulesContext( ScXMLImport& rImport,
608 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
609 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
610 ScXMLImportContext( rImport ),
611 pDatabaseRangeContext(pTempDatabaseRangeContext)
613 if ( !rAttrList.is() )
614 return;
616 for (auto &aIter : *rAttrList)
618 switch (aIter.getToken())
620 case XML_ELEMENT( TABLE, XML_BIND_STYLES_TO_CONTENT ):
621 pDatabaseRangeContext->SetSubTotalsBindFormatsToContent(IsXMLToken(aIter, XML_TRUE));
622 break;
623 case XML_ELEMENT( TABLE, XML_CASE_SENSITIVE ):
624 pDatabaseRangeContext->SetSubTotalsIsCaseSensitive(IsXMLToken(aIter, XML_TRUE));
625 break;
626 case XML_ELEMENT( TABLE, XML_PAGE_BREAKS_ON_GROUP_CHANGE ):
627 pDatabaseRangeContext->SetSubTotalsInsertPageBreaks(IsXMLToken(aIter, XML_TRUE));
628 break;
629 case XML_ELEMENT( LO_EXT, XML_SUMMARY_BELOW ):
630 pDatabaseRangeContext->SetSubTotalsSummaryBelow(IsXMLToken(aIter, XML_TRUE));
631 break;
636 ScXMLSubTotalRulesContext::~ScXMLSubTotalRulesContext()
640 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSubTotalRulesContext::createFastChildContext(
641 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
643 SvXMLImportContext *pContext = nullptr;
644 sax_fastparser::FastAttributeList *pAttribList =
645 &sax_fastparser::castToFastAttributeList( xAttrList );
647 switch (nElement)
649 case XML_ELEMENT( TABLE, XML_SORT_GROUPS ):
651 pContext = new ScXMLSortGroupsContext( GetScImport(), pAttribList, pDatabaseRangeContext);
653 break;
654 case XML_ELEMENT( TABLE, XML_SUBTOTAL_RULE ):
656 pContext = new ScXMLSubTotalRuleContext( GetScImport(), pAttribList, pDatabaseRangeContext);
658 break;
661 return pContext;
664 ScXMLSortGroupsContext::ScXMLSortGroupsContext( ScXMLImport& rImport,
665 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
666 ScXMLDatabaseRangeContext* pDatabaseRangeContext) :
667 ScXMLImportContext( rImport )
669 pDatabaseRangeContext->SetSubTotalsSortGroups(true);
670 if ( !rAttrList.is() )
671 return;
673 for (auto &aIter : *rAttrList)
675 switch (aIter.getToken())
677 case XML_ELEMENT( TABLE, XML_DATA_TYPE ):
679 const OUString sValue = aIter.toString();
680 if (sValue.getLength() > 8)
682 std::u16string_view sTemp = sValue.subView(0, 8);
683 if (sTemp == u"UserList")
685 pDatabaseRangeContext->SetSubTotalsEnabledUserList(true);
686 sTemp = sValue.subView(8);
687 pDatabaseRangeContext->SetSubTotalsUserListIndex(static_cast<sal_Int16>(o3tl::toInt32(sTemp)));
689 else
691 //if (IsXMLToken(aIter, XML_AUTOMATIC))
692 //aSortField.FieldType = util::SortFieldType_AUTOMATIC;
693 // is not supported by StarOffice
696 else
698 //if (IsXMLToken(aIter, XML_TEXT))
699 //aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
700 // is not supported by StarOffice
701 //else if (IsXMLToken(aIter, XML_NUMBER))
702 //aSortField.FieldType = util::SortFieldType_NUMERIC;
703 // is not supported by StarOffice
706 break;
707 case XML_ELEMENT( TABLE, XML_ORDER ):
709 if (IsXMLToken(aIter, XML_ASCENDING))
710 pDatabaseRangeContext->SetSubTotalsAscending(true);
711 else
712 pDatabaseRangeContext->SetSubTotalsAscending(false);
714 break;
719 ScXMLSortGroupsContext::~ScXMLSortGroupsContext()
723 ScXMLSubTotalRuleContext::ScXMLSubTotalRuleContext( ScXMLImport& rImport,
724 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
725 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
726 ScXMLImportContext( rImport ),
727 pDatabaseRangeContext(pTempDatabaseRangeContext)
729 if ( rAttrList.is() )
731 for (auto &aIter : *rAttrList)
733 switch (aIter.getToken())
735 case XML_ELEMENT( TABLE, XML_GROUP_BY_FIELD_NUMBER ):
736 aSubTotalRule.nSubTotalRuleGroupFieldNumber = static_cast<sal_Int16>(aIter.toInt32());
737 break;
743 ScXMLSubTotalRuleContext::~ScXMLSubTotalRuleContext()
747 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSubTotalRuleContext::createFastChildContext(
748 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
750 SvXMLImportContext *pContext = nullptr;
751 sax_fastparser::FastAttributeList *pAttribList =
752 &sax_fastparser::castToFastAttributeList( xAttrList );
754 switch (nElement)
756 case XML_ELEMENT( TABLE, XML_SUBTOTAL_FIELD ):
758 pContext = new ScXMLSubTotalFieldContext( GetScImport(), pAttribList, this);
760 break;
763 return pContext;
766 void SAL_CALL ScXMLSubTotalRuleContext::endFastElement( sal_Int32 /*nElement*/ )
768 if (pDatabaseRangeContext)
769 pDatabaseRangeContext->AddSubTotalRule(aSubTotalRule);
772 ScXMLSubTotalFieldContext::ScXMLSubTotalFieldContext( ScXMLImport& rImport,
773 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
774 ScXMLSubTotalRuleContext* pTempSubTotalRuleContext) :
775 ScXMLImportContext( rImport ),
776 pSubTotalRuleContext(pTempSubTotalRuleContext)
778 if ( !rAttrList.is() )
779 return;
781 for (auto &aIter : *rAttrList)
783 switch (aIter.getToken())
785 case XML_ELEMENT( TABLE, XML_FIELD_NUMBER ):
786 sFieldNumber = aIter.toString();
787 break;
788 case XML_ELEMENT( TABLE, XML_FUNCTION ):
789 sFunction = aIter.toString();
790 break;
795 ScXMLSubTotalFieldContext::~ScXMLSubTotalFieldContext()
799 void SAL_CALL ScXMLSubTotalFieldContext::endFastElement( sal_Int32 /*nElement*/ )
801 sheet::SubTotalColumn aSubTotalColumn;
802 aSubTotalColumn.Column = sFieldNumber.toInt32();
803 aSubTotalColumn.Function = ScXMLConverter::GetFunctionFromString( sFunction );
804 pSubTotalRuleContext->AddSubTotalColumn(aSubTotalColumn);
807 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */