20#include <config_features.h>
23#include <com/sun/star/sheet/TableValidationVisibility.hpp>
38#include <rtl/math.hxx>
39#include <osl/diagnose.h>
41#include <document.hxx>
50#include <tokenarray.hxx>
64 const OUString& rExpr1,
const OUString& rExpr2,
66 const OUString& rExprNmsp1,
const OUString& rExprNmsp2,
70 rExprNmsp2, eGrammar1, eGrammar2 )
76 , mnListType( css::sheet::TableValidationVisibility::UNSORTED )
89 , mnListType( css::sheet::TableValidationVisibility::UNSORTED )
96 , eDataMode( r.eDataMode )
97 , bShowInput( r.bShowInput )
98 , bShowError( r.bShowError )
99 , eErrorStyle( r.eErrorStyle )
100 , mnListType( r.mnListType )
101 , aInputTitle( r.aInputTitle )
102 , aInputMessage( r.aInputMessage )
103 , aErrorTitle( r.aErrorTitle )
104 , aErrorMessage( r.aErrorMessage )
112 , eDataMode( r.eDataMode )
113 , bShowInput( r.bShowInput )
114 , bShowError( r.bShowError )
115 , eErrorStyle( r.eErrorStyle )
116 , mnListType( r.mnListType )
117 , aInputTitle( r.aInputTitle )
118 , aInputMessage( r.aInputMessage )
119 , aErrorTitle( r.aErrorTitle )
120 , aErrorMessage( r.aErrorMessage )
194 bool bScriptReturnedFalse =
false;
197 css::uno::Any aParam0(rInput);
210 css::uno::Sequence< css::uno::Any > aParams{ aParam0, css::uno::Any(aPosStr) };
215 if ( !bWasInLinkUpdate )
222 css::uno::Sequence< sal_Int16 > aOutArgsIndex;
223 css::uno::Sequence< css::uno::Any > aOutArgs;
226 aErrorTitle, aParams, aRet, aOutArgsIndex, aOutArgs );
231 if ( !bWasInLinkUpdate )
242 bScriptReturnedFalse =
true;
250 VclMessageType::Warning, VclButtonsType::Ok,
251 ScResId(STR_VALID_MACRONOTFOUND)));
255 return bScriptReturnedFalse;
265 return DoScript( rPos, rInput, pCell, pParent );
280#if HAVE_FEATURE_SCRIPTING
290 SbModule* pModule = pMethod->GetModule();
293 pObject->GetName() +
"." + pModule->
GetName() +
"." + pMethod->GetName());
302 aBasicStr =
pObject->GetParent()->GetName();
310 OUString aValStr = rInput;
312 bool bIsValue =
false;
322 refPar->Get(1)->PutDouble(
nValue);
324 refPar->Get(1)->PutString(aValStr);
328 refPar->Get(2)->PutString(aPosStr);
333 if ( !bWasInLinkUpdate )
343 if ( !bWasInLinkUpdate )
352 if ( !bDone && !pCell )
356 VclMessageType::Warning, VclButtonsType::Ok,
357 ScResId(STR_VALID_MACRONOTFOUND)));
367 DoMacro( pCell->
aPos, OUString(), pCell,
nullptr );
381 return DoMacro(rPos, rInput,
nullptr, pParent);
386 if (aTitle.isEmpty())
387 aTitle =
ScResId( STR_MSSG_DOSUBTOTALS_0 );
389 if (aMessage.isEmpty())
390 aMessage =
ScResId( STR_VALID_DEFERROR );
397 eType = VclMessageType::Info;
398 eStyle = VclButtonsType::OkCancel;
401 eType = VclMessageType::Warning;
402 eStyle = VclButtonsType::OkCancel;
410 xBox->set_title(aTitle);
416 xBox->set_default_response(
RET_OK);
425 short nRet = xBox->run();
431 const OUString& rTest,
437 "ScValidationData::IsDataValidCustom invoked for a non-custom validation");
443 sal_uInt32 nFormat = 0;
445 OUString rStrResult =
"";
454 if (rStrResult.isEmpty())
529 nLen =
aStr.getLength();
545 sal_uInt32 nFormat = 0;
547 OUString rStrResult =
"";
556 if (rStrResult.isEmpty())
649 bOk = ::rtl::math::approxEqual( nVal, floor(nVal+0.5) );
665 OSL_FAIL(
"not yet done");
673 OUString& rStrResult,
double& nVal, sal_uInt32& nFormat,
bool& bIsVal)
const
675 std::optional<ScSimpleFormulaCalculator> pFCell(std::in_place, *
mpDoc, rPos, rTest,
true);
676 pFCell->SetLimitString(
true);
678 bool bColRowName = pFCell->HasColRowName();
682 if (pFCell->GetCode()->GetCodeLen() <= 1)
685 OUString aBraced =
"(" + rTest +
")";
686 pFCell.emplace(*
mpDoc, rPos, aBraced,
true);
687 pFCell->SetLimitString(
true);
694 if (nErrCode == FormulaError::NONE || pFCell->IsMatrix())
698 if (pFCell->IsMatrix())
700 rStrResult = pFCell->GetString().getString();
702 else if (pFCell->IsValue())
704 nVal = pFCell->GetValue();
715 rStrResult, &pColor);
720 rStrResult =
"\"" + rStrResult.replaceAll(
"\"",
"\"\"") +
"\"";
725 rStrResult +=
" ...";
741class ScStringTokenIterator
744 explicit ScStringTokenIterator(
const ScTokenArray& rTokArr ) :
745 maIter( rTokArr ), mbOk( true ) {}
748 rtl_uString*
First();
753 bool Ok()
const {
return mbOk; }
761rtl_uString* ScStringTokenIterator::First()
768rtl_uString* ScStringTokenIterator::Next()
775 while( pToken && (pToken->
GetOpCode() == ocSep) )
776 pToken =
maIter.NextNoSpaces();
785 return (maCurString.isValid() && maCurString.isEmpty()) ?
Next() : maCurString.getData();
812 if(
nullptr == pDocument )
834 if (nErrCode != FormulaError::NONE)
841 xMatRef->PutError( nErrCode, 0, 0);
844 else if (aValidationSrc.
IsValue())
845 xMatRef->PutDouble( aValidationSrc.
GetValue(), 0);
849 xMatRef->PutString(
aStr, 0);
861 SCSIZE nCol, nRow, nCols, nRows,
n = 0;
862 pValues->GetDimensions( nCols, nRows );
874 OpCode eOpCode =
t->GetOpCode();
879 pDBData->GetArea(aRange);
883 else if (eOpCode ==
ocName)
901 bool bHaveEmpty =
false;
910 for( nRow = 0; nRow < nRows ; nRow++ )
912 for( nCol = 0; nCol < nCols ; nCol++ )
915 std::unique_ptr<ScTypedStrData> pEntry;
927 if (aValStr.isEmpty())
934 if(
nullptr != pStrings )
937 if (!rCell.
isEmpty() && rMatch < 0)
944 if( FormulaError::NONE != nErr )
965 if (!rCell.
isEmpty() && rMatch < 0)
971 if(
nullptr != pStrings )
979 if(
nullptr == pStrings )
986 pStrings->push_back(*pEntry);
1007 sal_uInt32 nFormat = lclGetCellFormat( *
GetDocument(), rPos );
1008 ScStringTokenIterator aIt( *pTokArr );
1009 for (rtl_uString* pString = aIt.First(); pString && aIt.Ok(); pString = aIt.Next())
1012 OUString
aStr(pString);
1014 rStrColl.emplace_back(
1042 bool bIsValid =
false;
1060 sal_uInt32 nFormat = lclGetCellFormat( *
GetDocument(), rPos );
1061 ScStringTokenIterator aIt( *pTokArr );
1062 for (rtl_uString* pString = aIt.First(); pString && aIt.Ok(); pString = aIt.Next())
1071 OUString
aStr(pString);
1072 if (
GetDocument()->GetFormatTable()->IsNumberFormat(
aStr, nFormat, fValue))
1091 bIsValid = bIsValid && nMatch >= 0;
1101 for (
const auto& rxItem : rList)
1103 InsertNew( std::unique_ptr<ScValidationData>(rxItem->Clone()) );
1114 for (
const auto& rxItem : rList)
1116 InsertNew( std::unique_ptr<ScValidationData>(rxItem->Clone(&rNewDoc)) );
1127 if( (*it)->GetKey() == nKey )
1130 OSL_FAIL(
"ScValidationDataList: Entry not found");
1137 (*it)->CompileXML();
1143 (*it)->UpdateReference(rCxt);
1149 (*it)->UpdateInsertTab(rCxt);
1155 (*it)->UpdateDeleteTab(rCxt);
1161 (*it)->UpdateMoveTab(rCxt);
const PropertyValue * pValues
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
std::vector< Reference< XAnimationNode > >::iterator maIter
SfxApplication * SfxGetpApp()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const SbxObject * GetParent() const
const OUString & GetName(SbxNameType=SbxNameType::NONE) const
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
ScDocument * GetDocument() const
std::unique_ptr< ScTokenArray > CreateFlatCopiedTokenArray(sal_uInt16 nPos) const
Create a flat copy using ScTokenArray copy-ctor with shared tokens.
bool IsIgnoreBlank() const
bool IsCellValid(ScRefCellValue &rCell, const ScAddress &rPos) const
ScDBData * findByIndex(sal_uInt16 nIndex)
SC_DLLPUBLIC sal_uInt32 GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab) const
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
ScRangeData * FindRangeNameBySheetAndIndex(SCTAB nTab, sal_uInt16 nIndex) const
Find a named expression / range name in either global or a local scope.
bool IsInLinkUpdate() const
void SetInLinkUpdate(bool bSet)
SC_DLLPUBLIC OUString GetInputString(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bForceSystemLocale=false) const
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
SfxObjectShell * GetDocumentShell() const
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
void LockTable(SCTAB nTab)
void UnlockTable(SCTAB nTab)
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
static SC_DLLPUBLIC OUString GetString(const EditTextObject &rEditText, const ScDocument *pDoc)
Retrieves string with paragraphs delimited by new lines (' ').
bool operator==(const ScFormatEntry &) const
static SC_DLLPUBLIC LanguageType eLnge
static OUString GetErrorString(FormulaError nErrNumber)
Matrix data type that can store values of mixed types.
static bool IsNonValueType(ScMatValType nType)
String, empty or empty path, but not value nor boolean.
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
ScRefFlags Parse(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, ScAddress::ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, const OUString *pErrRef=nullptr)
bool IsValidReference(ScRange &rRange, const ScAddress &rPos) const
Exactly and only one valid range (no #REF!s)
ScValidationDataListDataType::iterator iterator
ScValidationDataListDataType maData
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt)
void UpdateReference(sc::RefUpdateContext &rCxt)
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt)
void InsertNew(std::unique_ptr< ScValidationData > pNew)
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt)
ScValidationData * GetData(sal_uInt32 nKey)
ScValidationDataListDataType::const_iterator const_iterator
bool IsListValid(ScRefCellValue &rCell, const ScAddress &rPos) const
Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list.
bool IsDataValidCustom(const OUString &rTest, const ScPatternAttr &rPattern, const ScAddress &rPos, const CustomValidationPrivateAccess &) const
bool isFormulaResultsValidatable(const OUString &rTest, const ScAddress &rPos, SvNumberFormatter *pFormatter, OUString &rStrResult, double &nVal, sal_uInt32 &nFormat, bool &bIsVal) const
Test, if formula is valid.
bool IsDataValidTextLen(std::u16string_view rTest, const ScAddress &rPos, ScValidationDataIsNumeric *pDataNumeric) const
Tests, if string or numeric data has valid text length.
bool DoScript(const ScAddress &rPos, const OUString &rInput, ScFormulaCell *pCell, weld::Window *pParent) const
ScValidationData(ScValidationMode eMode, ScConditionMode eOper, const OUString &rExpr1, const OUString &rExpr2, ScDocument &rDocument, const ScAddress &rPos, const OUString &rExprNmsp1=OUString(), const OUString &rExprNmsp2=OUString(), formula::FormulaGrammar::Grammar eGrammar1=formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::Grammar eGrammar2=formula::FormulaGrammar::GRAM_DEFAULT)
bool IsDataValid(const OUString &rTest, const ScPatternAttr &rPattern, const ScAddress &rPos) const
ScValidationMode GetDataMode() const
ScValidationMode eDataMode
bool GetSelectionFromFormula(std::vector< ScTypedStrData > *pStrings, ScRefCellValue &rCell, const ScAddress &rPos, const ScTokenArray &rTokArr, int &rMatch) const
Tries to fill the passed collection with list validation entries.
ScValidErrorStyle eErrorStyle
bool EqualEntries(const ScValidationData &r) const
void DoCalcError(ScFormulaCell *pCell) const
bool FillSelectionList(std::vector< ScTypedStrData > &rStrings, const ScAddress &rPos) const
Tries to fill the passed collection with list validation entries.
bool GetErrMsg(OUString &rTitle, OUString &rMsg, ScValidErrorStyle &rStyle) const
void SetInput(const OUString &rTitle, const OUString &rMsg)
bool HasSelectionList() const
Returns true, if the validation cell will show a selection list.
virtual ~ScValidationData() override
bool IsEqualToTokenArray(ScRefCellValue &rCell, const ScAddress &rPos, const ScTokenArray &rTokArr) const
Tests, if pCell is equal to what the passed token array represents.
void SetError(const OUString &rTitle, const OUString &rMsg, ScValidErrorStyle eStyle)
bool DoMacro(const ScAddress &rPos, const OUString &rInput, ScFormulaCell *pCell, weld::Window *pParent) const
bool DoError(weld::Window *pParent, const OUString &rInput, const ScAddress &rPos) const
static bool IsXScriptURL(const OUString &rScriptURL)
ErrCode CallXScript(const OUString &rScriptURL, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Any &aRet, css::uno::Sequence< sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam, bool bRaiseError=true, const css::uno::Any *aCaller=nullptr)
StarBASIC * GetBasic() const
ErrCode CallBasic(std::u16string_view rMacro, std::u16string_view rBasicName, SbxArray *pArgs, SbxValue *pRet=nullptr)
const OUString & GetName() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
virtual SbxVariable * Find(const OUString &, SbxClassType) override
SharedString intern(const OUString &rStr)
const OUString & getString() const
EmbeddedObjectRef * pObject
#define LINK(Instance, Class, Member)
#define ERRCODE_BASIC_METHOD_NOT_FOUND
OUString ScResId(TranslateId aId)
Store arbitrary cell value of any kind.
void commit(ScDocument &rDoc, const ScAddress &rPos) const
Set cell value at specified position in specified document.
Try NOT to use this struct.
FormulaError GetError() const
Only valid if ScMatrix methods indicate that this is no string!
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
This is very similar to ScCellValue, except that it references the original value instead of copying ...
ScFormulaCell * getFormula() const
const EditTextObject * getEditText() const
void commit(ScDocument &rDoc, const ScAddress &rPos) const
Set cell value at specified position in specified document.
const svl::SharedString * getSharedString() const
To test numeric data text length in IsDataValidTextLen().
ScValidationDataIsNumeric(double fVal, SvNumberFormatter *pFormatter=nullptr, sal_uInt32 nFormat=0)
SvNumberFormatter * mpFormatter
void init(const ScDocument &rDoc, const ScAddress &rPos)
Context for reference update during shifting, moving or copying of cell ranges.
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
IMPL_STATIC_LINK_NOARG(ScValidationData, InstallLOKNotifierHdl, void *, vcl::ILibreOfficeKitNotifier *)