22#include <unonames.hxx>
24#include <document.hxx>
30#include <com/sun/star/uno/Reference.h>
31#include <com/sun/star/beans/XPropertySet.hpp>
32#include <com/sun/star/sheet/XSheetCondition.hpp>
33#include <com/sun/star/sheet/TableValidationVisibility.hpp>
39#include <osl/diagnose.h>
45 : aAlertStyle(sheet::ValidationAlertStyle_STOP),
46 aValidationType(sheet::ValidationType_ANY),
47 aOperator(sheet::ConditionOperator_NONE),
49 bShowErrorMessage(false),
50 bShowInputMessage(false),
81 sal_Int32& nValidationIndex)
83 uno::Reference<beans::XPropertySet> xPropertySet(aTempAny, uno::UNO_QUERY);
84 if (!xPropertySet.is())
87 OUString sErrorMessage;
91 OUString sInputMessage;
95 bool bShowErrorMessage = ::cppu::any2bool(xPropertySet->getPropertyValue(
SC_UNONAME_SHOWERR));
96 bool bShowInputMessage = ::cppu::any2bool(xPropertySet->getPropertyValue(
SC_UNONAME_SHOWINP));
97 sheet::ValidationType aValidationType;
99 if (!bShowErrorMessage && !bShowInputMessage && aValidationType == sheet::ValidationType_ANY &&
100 sErrorMessage.isEmpty() && sErrorTitle.isEmpty() && sInputMessage.isEmpty() && sInputTitle.isEmpty())
114 uno::Reference<sheet::XSheetCondition> xCondition(xPropertySet, uno::UNO_QUERY);
117 aValidation.
sFormula1 = xCondition->getFormula1();
118 aValidation.
sFormula2 = xCondition->getFormula2();
119 aValidation.
aOperator = xCondition->getOperator();
120 table::CellAddress aCellAddress= xCondition->getSourcePosition();
124 bool bEqualFound(
false);
127 while (
i <
nCount && !bEqualFound)
134 nValidationIndex =
i;
137 sal_Int32 nNameIndex(
nCount + 1);
138 OUString sCount(OUString::number(nNameIndex));
139 aValidation.
sName +=
"val";
140 aValidation.
sName += sCount;
142 nValidationIndex =
nCount;
158 case sheet::ValidationType_DATE :
159 sCondition +=
"cell-content-is-date()";
161 case sheet::ValidationType_DECIMAL :
162 sCondition +=
"cell-content-is-decimal-number()";
164 case sheet::ValidationType_LIST :
165 sCondition +=
"cell-content-is-in-list(" + aValidation.
sFormula1 +
")";
167 case sheet::ValidationType_TEXT_LEN :
168 if (aValidation.
aOperator != sheet::ConditionOperator_BETWEEN &&
169 aValidation.
aOperator != sheet::ConditionOperator_NOT_BETWEEN)
170 sCondition +=
"cell-content-text-length()";
172 case sheet::ValidationType_TIME :
173 sCondition +=
"cell-content-is-time()";
175 case sheet::ValidationType_WHOLE :
176 sCondition +=
"cell-content-is-whole-number()";
178 case sheet::ValidationType_CUSTOM :
179 sCondition +=
"is-true-formula(" + aValidation.
sFormula1 +
")";
189 ((aValidation.
aOperator == sheet::ConditionOperator_BETWEEN ||
190 aValidation.
aOperator == sheet::ConditionOperator_NOT_BETWEEN) &&
194 sCondition +=
" and ";
195 if (aValidation.
aOperator != sheet::ConditionOperator_BETWEEN &&
196 aValidation.
aOperator != sheet::ConditionOperator_NOT_BETWEEN)
199 sCondition +=
"cell-content()";
202 case sheet::ConditionOperator_EQUAL :
205 case sheet::ConditionOperator_GREATER :
208 case sheet::ConditionOperator_GREATER_EQUAL :
211 case sheet::ConditionOperator_LESS :
214 case sheet::ConditionOperator_LESS_EQUAL :
217 case sheet::ConditionOperator_NOT_EQUAL :
231 if (aValidation.
aOperator == sheet::ConditionOperator_BETWEEN)
232 sCondition +=
"cell-content-text-length-is-between(";
234 sCondition +=
"cell-content-text-length-is-not-between(";
238 if (aValidation.
aOperator == sheet::ConditionOperator_BETWEEN)
239 sCondition +=
"cell-content-is-between(";
241 sCondition +=
"cell-content-is-not-between(";
250 if (!sCondition.isEmpty())
268 const OUString& sTitle,
const OUString& sOUMessage,
269 const bool bShowMessage,
const bool bIsHelpMessage)
271 if (!sTitle.isEmpty())
277 std::unique_ptr<SvXMLElementExport> pMessage;
282 if (sOUMessage.isEmpty())
286 OUStringBuffer sTemp;
288 bool bPrevCharWasSpace(
true);
289 while(
i < sText.getLength())
291 if( sText[
i] ==
'\n')
295 bPrevCharWasSpace =
true;
298 sTemp.append(sText[
i]);
301 if (!sTemp.isEmpty())
317 OUString sCondition(
GetCondition(rExport, rValidation));
318 if (!sCondition.isEmpty())
321 if (rValidation.bIgnoreBlanks)
325 if (rValidation.aValidationType == sheet::ValidationType_LIST)
327 switch (rValidation.nShowList)
329 case sheet::TableValidationVisibility::INVISIBLE:
332 case sheet::TableValidationVisibility::UNSORTED:
335 case sheet::TableValidationVisibility::SORTEDASCENDING:
339 OSL_FAIL(
"unknown ListType");
345 if (rValidation.bShowInputMessage || !rValidation.sInputMessage.isEmpty() || !rValidation.sInputTitle.isEmpty())
347 WriteMessage(rExport, rValidation.sInputTitle, rValidation.sInputMessage, rValidation.bShowInputMessage,
true);
349 if (rValidation.bShowErrorMessage || !rValidation.sErrorMessage.isEmpty() || !rValidation.sErrorTitle.isEmpty())
351 switch (rValidation.aAlertStyle)
353 case sheet::ValidationAlertStyle_INFO :
356 WriteMessage(rExport, rValidation.sErrorTitle, rValidation.sErrorMessage, rValidation.bShowErrorMessage,
false);
359 case sheet::ValidationAlertStyle_WARNING :
362 WriteMessage(rExport, rValidation.sErrorTitle, rValidation.sErrorMessage, rValidation.bShowErrorMessage,
false);
365 case sheet::ValidationAlertStyle_STOP :
368 WriteMessage(rExport, rValidation.sErrorTitle, rValidation.sErrorMessage, rValidation.bShowErrorMessage,
false);
371 case sheet::ValidationAlertStyle_MACRO :
375 if (rValidation.bShowErrorMessage)
387 static constexpr OUStringLiteral
sScript(
u"Script");
389 {
"EventType",
uno::Any(bScriptURL ?
sScript : OUString(
"StarBasic")) },
390 {
"Library",
uno::Any(OUString()) },
391 { bScriptURL ?
sScript : OUString(
"MacroName"),
uno::Any(rValidation.sErrorTitle) }
414 const sal_Int32 nTable,
const sal_Int32 nPos,
415 const sal_Int32 i,
bool& bIsAutoStyle)
421 const sal_Int32 nLastRow,
const sal_Int32 nLastCol,
433 bool bPrevAutoStyle(
false);
435 sal_Int32 nPrevIndex(0);
436 sal_Int32 nRepeat(0);
437 for (sal_Int32
i = nLastCol;
i >= 0; --
i)
443 (*pDefaults)[
i].nIndex = nPrevIndex;
444 (*pDefaults)[
i].bIsAutoStyle = bPrevAutoStyle;
450 if ((
nIndex != nPrevIndex) || (bIsAutoStyle != bPrevAutoStyle))
454 (*pDefaults)[
i].nIndex = nPrevIndex;
455 (*pDefaults)[
i].bIsAutoStyle = bPrevAutoStyle;
459 (*pDefaults)[
i].nIndex = nPrevIndex;
460 (*pDefaults)[
i].bIsAutoStyle = bPrevAutoStyle;
463 (*pDefaults)[
i].nRepeat = nRepeat;
474 nValidationIndex(-1),
485 : pColDefaults(nullptr),
491 : aRowFormatRanges(pRanges->aRowFormatRanges),
492 pColDefaults(pRanges->pColDefaults),
493 nSize(pRanges->nSize)
511 if ((nPrevIndex != rFormatRange.
nIndex) ||
515 bool bInserted(
false);
548 sal_Int32 nPrevIndex = -1;
549 bool bPrevAutoStyle =
true;
552 OSL_ENSURE(
static_cast<size_t>(nPrevStartCol) <
pColDefaults->size(),
"nPrevStartCol out of bounds");
554 if (
static_cast<size_t>(nPrevStartCol) <
pColDefaults->size())
556 nRepeat = (*pColDefaults)[nPrevStartCol].nRepeat;
557 nPrevIndex = (*pColDefaults)[nPrevStartCol].nIndex;
558 bPrevAutoStyle = (*pColDefaults)[nPrevStartCol].bIsAutoStyle;
568 bPrevAutoStyle =
false;
572 nRepeat = (*pColDefaults)[
pColDefaults->size()-1].nRepeat;
573 nPrevIndex = (*pColDefaults)[
pColDefaults->size()-1].nIndex;
574 bPrevAutoStyle = (*pColDefaults)[
pColDefaults->size()-1].bIsAutoStyle;
578 for(sal_uInt32
i = nPrevStartCol + nRepeat;
i < nEnd &&
i <
pColDefaults->size();
i += (*pColDefaults)[
i].nRepeat)
580 OSL_ENSURE(sal_uInt32(nPrevStartCol + nRepeat) <= nEnd,
"something went wrong");
584 AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
586 nRepeat = (*pColDefaults)[
i].nRepeat;
587 nPrevIndex = (*pColDefaults)[
i].nIndex;
588 bPrevAutoStyle = (*pColDefaults)[
i].bIsAutoStyle;
591 nRepeat += (*pColDefaults)[
i].nRepeat;
593 if (sal_uInt32(nPrevStartCol + nRepeat) > nEnd)
594 nRepeat = nEnd - nPrevStartCol;
595 AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
604 aFormatRange = *aItr;
614 sal_Int32 nMaxRows(0);
619 nMaxRows = (*aItr).nRepeatRows;
623 OSL_FAIL(
"no ranges found");
634 : nStyleNameIndex(-1)
635 , nValidationIndex(-1)
653 : pColDefaults(nullptr)
663 sal_Int32 nSize =
aTables.size() - 1;
665 for (sal_Int32
i = nSize;
i < nTable; ++
i)
684 while ((
i >= 0) && (!bFound))
707 sal_Int32 nPrefixLength(rPrefix.size());
708 std::u16string_view sTemp(rString.substr(nPrefixLength));
728 bIsAutoStyle =
false;
753 const sal_Int32 nColumn,
const sal_Int32 nRow,
bool& bIsAutoStyle)
const
756 bIsAutoStyle =
false;
761 if ((rFormatRange.aRangeAddress.StartColumn <= nColumn) &&
762 (rFormatRange.aRangeAddress.EndColumn >= nColumn) &&
763 (rFormatRange.aRangeAddress.StartRow <= nRow) &&
764 (rFormatRange.aRangeAddress.EndRow >= nRow))
766 bIsAutoStyle = rFormatRange.bIsAutoStyle;
767 return rFormatRange.nStyleNameIndex;
774 bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat,
const sal_Int32 nRemoveBeforeRow)
780 ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
781 ScMyFormatRangeAddresses::iterator aEndItr(rFormatRanges.end());
782 while (aItr != aEndItr)
784 if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
785 ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
786 ((*aItr).aRangeAddress.StartRow <= nRow) &&
787 ((*aItr).aRangeAddress.EndRow >= nRow))
789 bIsAutoStyle = aItr->bIsAutoStyle;
790 nValidationIndex = aItr->nValidationIndex;
791 nNumberFormat = aItr->nNumberFormat;
795 ((*
pColDefaults)[nColumn].nIndex == (*aItr).nStyleNameIndex) &&
796 ((*
pColDefaults)[nColumn].bIsAutoStyle == (*aItr).bIsAutoStyle))
799 return (*aItr).nStyleNameIndex;
803 if ((*aItr).aRangeAddress.EndRow < nRemoveBeforeRow)
804 aItr = rFormatRanges.erase(aItr);
815 sal_Int32 nTotalColumns(nEndColumn - nStartColumn + 1);
818 ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
819 ScMyFormatRangeAddresses::iterator aEndItr(rFormatRanges.end());
820 sal_Int32 nColumns = 0;
821 while (aItr != aEndItr && nColumns < nTotalColumns)
823 if (((*aItr).aRangeAddress.StartRow <= nRow) &&
824 ((*aItr).aRangeAddress.EndRow >= nRow))
826 if ((((*aItr).aRangeAddress.StartColumn <= nStartColumn) &&
827 ((*aItr).aRangeAddress.EndColumn >= nStartColumn)) ||
828 (((*aItr).aRangeAddress.StartColumn <= nEndColumn) &&
829 ((*aItr).aRangeAddress.EndColumn >= nEndColumn)) ||
830 (((*aItr).aRangeAddress.StartColumn >= nStartColumn) &&
831 ((*aItr).aRangeAddress.EndColumn <= nEndColumn)))
834 aRange.
nIndex = aItr->nStyleNameIndex;
837 if ((aItr->aRangeAddress.StartColumn < nStartColumn) &&
838 (aItr->aRangeAddress.EndColumn >= nStartColumn))
840 if (aItr->aRangeAddress.EndColumn >= nEndColumn)
843 aRange.
nRepeatColumns = aItr->aRangeAddress.EndColumn - nStartColumn + 1;
846 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
847 (aItr->aRangeAddress.EndColumn <= nEndColumn))
849 aRange.
nRepeatColumns = aItr->aRangeAddress.EndColumn - aItr->aRangeAddress.StartColumn + 1;
852 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
853 (aItr->aRangeAddress.StartColumn <= nEndColumn) &&
854 (aItr->aRangeAddress.EndColumn > nEndColumn))
856 aRange.
nRepeatColumns = nEndColumn - aItr->aRangeAddress.StartColumn + 1;
859 aRange.
nRepeatRows = aItr->aRangeAddress.EndRow - nRow + 1;
866 if(aItr->aRangeAddress.EndRow < nRow)
867 aItr = rFormatRanges.erase(aItr);
871 pRowFormatRanges->
Sort();
875 const sal_Int32 nStringIndex,
const bool bIsAutoStyle,
const sal_Int32 nValidationIndex,
876 const sal_Int32 nNumberFormat)
886 rFormatRanges.push_back(aFormatRange);
919 sal_Int32 nPrefixLength(rPrefix.size());
920 std::u16string_view sTemp(rString.substr(nPrefixLength));
957 sal_Int32 nSize(
aTables.size() - 1);
959 for (sal_Int32
i = nSize;
i < nTable; ++
i)
972 bIsVisible =
aTables[nTable][nField].bIsVisible;
973 return aTables[nTable][nField].nIndex;
977 bIsVisible =
aTables[nTable][
aTables[nTable].size() - 1].bIsVisible;
983 const sal_Int32 nStringIndex,
const bool bIsVisible)
988 aStyle.
nIndex = nStringIndex;
990 if (
aTables[nTable].
size() ==
static_cast<sal_uInt32
>(nField))
991 aTables[nTable].push_back(aStyle);
992 aTables[nTable][nField] = aStyle;
1000 return mnTable == nTable &&
mnStart <= nField && nField <
mnEnd;
1013 sal_Int32 nSize(
aTables.size() - 1);
1015 for (sal_Int32
i = nSize;
i < nTable; ++
i)
1017 aTables.push_back(std::make_unique<StylesType>(0, nFields+1, -1));
1032 if (!r.is_tree_valid())
1034 sal_Int32 nStyle(0);
1035 sal_Int32 nStart(0), nEnd(0);
1036 if (r.search_tree(nField, nStyle, &nStart, &nEnd).second)
1050 const sal_Int32 nStringIndex)
1054 r.insert_back(nField, nField+1, nStringIndex);
1058 const sal_Int32 nStringIndex,
const sal_Int32 nEndField)
1060 OSL_ENSURE( nStartField <= nEndField,
"bad field range");
1063 r.insert_back(nStartField, nEndField+1, nStringIndex);
std::vector< ScMyDefaultStyle > ScMyDefaultStyleList
std::vector< OUString > aStyleNames
virtual ~ScColumnRowStylesBase()
OUString & GetStyleNameByIndex(const sal_Int32 nIndex)
sal_Int32 GetIndexOfStyleName(std::u16string_view rString, std::u16string_view rPrefix)
sal_Int32 AddStyleName(const OUString &rString)
sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField, bool &bIsVisible)
virtual ~ScColumnStyles() override
virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) override
void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex, const bool bIsVisible)
ScMyColumnVectorVec aTables
std::vector< ScColumnStyle > ScMyColumnStyleVec
void GetColDefault(SCTAB nTab, SCCOL nCol, SCROW nLastRow, SCROW &nDefault)
void CreateColumnIfNotExists(SCTAB nTab, SCCOL nCol)
formula::FormulaGrammar::Grammar GetStorageGrammar() const
ScMyDefaultStyleList maColDefaults
static sal_Int32 GetStyleNameIndex(const ScFormatRangeStyles *pCellStyles, const sal_Int32 nTable, const sal_Int32 nPos, const sal_Int32 i, bool &bIsAutoStyle)
void FillDefaultStyles(const sal_Int32 nTable, const sal_Int32 nLastRow, const sal_Int32 nLastCol, const ScFormatRangeStyles *pCellStyles, ScDocument *pDoc)
const OUString & GetValidationName(const sal_Int32 nIndex)
static OUString GetBaseCellAddress(const ScDocument *pDoc, const ScAddress &aCell)
ScMyValidationsContainer()
void AddValidation(const css::uno::Any &aAny, sal_Int32 &nValidationIndex)
static void WriteMessage(ScXMLExport &rExport, const OUString &sTitle, const OUString &sMessage, const bool bShowMessage, const bool bIsHelpMessage)
std::vector< ScMyValidation > aValidationVec
~ScMyValidationsContainer()
static OUString GetCondition(ScXMLExport &rExport, const ScMyValidation &aValidation)
void WriteValidations(ScXMLExport &rExport)
static void GetStringFromAddress(OUString &rString, const ScAddress &rAddress, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ', bool bAppendStr=false, ScRefFlags nFormatFlags=ScRefFlags::VALID|ScRefFlags::TAB_3D)
Range to String core.
::mdds::flat_segment_tree< sal_Int32, sal_Int32 > StylesType
void AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField, const sal_Int32 nStringIndex)
virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) override
std::vector< std::unique_ptr< StylesType > > aTables
sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
virtual ~ScRowStyles() override
ScDocument * GetDocument()
static bool IsXScriptURL(const OUString &rScriptURL)
const SvXMLNamespaceMap & GetNamespaceMap() const
XMLEventExport & GetEventExport()
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
void ExportSingleEvent(const css::uno::Sequence< css::beans::PropertyValue > &rEventValues, const OUString &rApiEventName, bool bUseWhitespace=true)
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
Sequence< sal_Int8 > aSeq
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
css::sheet::ValidationAlertStyle aAlertStyle
css::sheet::ConditionOperator aOperator
bool IsEqual(const ScMyValidation &aVal) const
css::sheet::ValidationType aValidationType
bool hasCache(sal_Int32 nTable, sal_Int32 nField) const
constexpr OUStringLiteral sScript
constexpr OUStringLiteral SC_UNONAME_SHOWINP
constexpr OUStringLiteral SC_UNONAME_SHOWERR
constexpr OUStringLiteral SC_UNONAME_IGNOREBL
constexpr OUStringLiteral SC_UNONAME_ERRALSTY
constexpr OUStringLiteral SC_UNONAME_TYPE
constexpr OUStringLiteral SC_UNONAME_INPMESS
constexpr OUStringLiteral SC_UNONAME_ERRTITLE
constexpr OUStringLiteral SC_UNONAME_ERRMESS
constexpr OUStringLiteral SC_UNONAME_SHOWLIST
constexpr OUStringLiteral SC_UNONAME_INPTITLE
constexpr sal_uInt16 XML_NAMESPACE_OOOC
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_OF
constexpr sal_uInt16 XML_NAMESPACE_TABLE