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>
44 #include <globstr.hrc>
50 #include <tokenarray.hxx>
63 const OUString& rExpr1,
const OUString& rExpr2,
65 const OUString& rExprNmsp1,
const OUString& rExprNmsp2,
69 rExprNmsp2, eGrammar1, eGrammar2 )
75 , mnListType(
css::
sheet::TableValidationVisibility::UNSORTED )
88 , mnListType(
css::
sheet::TableValidationVisibility::UNSORTED )
95 , eDataMode( r.eDataMode )
96 , bShowInput( r.bShowInput )
97 , bShowError( r.bShowError )
98 , eErrorStyle( r.eErrorStyle )
99 , mnListType( r.mnListType )
100 , aInputTitle( r.aInputTitle )
101 , aInputMessage( r.aInputMessage )
102 , aErrorTitle( r.aErrorTitle )
103 , aErrorMessage( r.aErrorMessage )
111 , eDataMode( r.eDataMode )
112 , bShowInput( r.bShowInput )
113 , bShowError( r.bShowError )
114 , eErrorStyle( r.eErrorStyle )
115 , mnListType( r.mnListType )
116 , aInputTitle( r.aInputTitle )
117 , aInputMessage( r.aInputMessage )
118 , aErrorTitle( r.aErrorTitle )
119 , aErrorMessage( r.aErrorMessage )
193 bool bScriptReturnedFalse =
false;
196 css::uno::Sequence< css::uno::Any > aParams(2);
199 OUString aValStr = rInput;
201 bool bIsValue =
false;
211 aParams[0] <<= nValue;
213 aParams[0] <<= aValStr;
217 aParams[1] <<= aPosStr;
222 if ( !bWasInLinkUpdate )
229 css::uno::Sequence< sal_Int16 > aOutArgsIndex;
230 css::uno::Sequence< css::uno::Any > aOutArgs;
233 aErrorTitle, aParams, aRet, aOutArgsIndex, aOutArgs );
238 if ( !bWasInLinkUpdate )
249 bScriptReturnedFalse =
true;
257 VclMessageType::Warning, VclButtonsType::Ok,
258 ScResId(STR_VALID_MACRONOTFOUND)));
262 return bScriptReturnedFalse;
272 return DoScript( rPos, rInput, pCell, pParent );
287 #if HAVE_FEATURE_SCRIPTING
295 if (
SbMethod* pMethod = dynamic_cast<SbMethod*>(pVar))
297 SbModule* pModule = pMethod->GetModule();
299 OUStringBuffer aMacroStr = pObject->
GetName();
300 aMacroStr.append(
'.').append(pModule->
GetName()).append(
'.').append(pMethod->GetName());
317 OUString aValStr = rInput;
319 bool bIsValue =
false;
340 if ( !bWasInLinkUpdate )
346 ErrCode eRet = pDocSh->
CallBasic( aMacroStr.makeStringAndClear(), aBasicStr, refPar.
get(), refRes.
get() );
350 if ( !bWasInLinkUpdate )
359 if ( !bDone && !pCell )
363 VclMessageType::Warning, VclButtonsType::Ok,
364 ScResId(STR_VALID_MACRONOTFOUND)));
383 return DoMacro(rPos, rInput,
nullptr, pParent);
388 if (aTitle.isEmpty())
389 aTitle =
ScResId( STR_MSSG_DOSUBTOTALS_0 );
391 if (aMessage.isEmpty())
392 aMessage =
ScResId( STR_VALID_DEFERROR );
399 eType = VclMessageType::Info;
400 eStyle = VclButtonsType::OkCancel;
403 eType = VclMessageType::Warning;
404 eStyle = VclButtonsType::OkCancel;
414 eStyle, aMessage, bIsMobile));
415 xBox->set_title(aTitle);
420 xBox->set_default_response(
RET_OK);
429 short nRet = xBox->run();
435 const OUString& rTest,
441 "ScValidationData::IsDataValidCustom invoked for a non-custom validation");
491 : mpFormatter(pFormatter), mfVal(fVal), mnFormat(nFormat)
508 nLen = rTest.getLength();
520 nLen = aStr.getLength();
625 bOk = ::rtl::math::approxEqual( nVal, floor(nVal+0.5) );
641 OSL_FAIL(
"not yet done");
653 class ScStringTokenIterator
656 explicit ScStringTokenIterator(
const ScTokenArray& rTokArr ) :
657 maIter( rTokArr ), mbOk( true ) {}
660 rtl_uString*
First();
665 bool Ok()
const {
return mbOk; }
673 rtl_uString* ScStringTokenIterator::First()
680 rtl_uString* ScStringTokenIterator::Next()
688 pToken =
maIter.NextNoSpaces();
697 return (maCurString.isValid() && maCurString.isEmpty()) ?
Next() : maCurString.getData();
724 if(
nullptr == pDocument )
746 if (nErrCode != FormulaError::NONE)
753 xMatRef->PutError( nErrCode, 0, 0);
756 else if (aValidationSrc.
IsValue())
757 xMatRef->PutDouble( aValidationSrc.
GetValue(), 0);
761 xMatRef->PutString(aStr, 0);
764 pValues = xMatRef.get();
772 SCSIZE nCol, nRow, nCols, nRows,
n = 0;
790 pDBData->GetArea(aRange);
794 else if (eOpCode ==
ocName)
812 bool bHaveEmpty =
false;
821 for( nRow = 0; nRow < nRows ; nRow++ )
823 for( nCol = 0; nCol < nCols ; nCol++ )
826 std::unique_ptr<ScTypedStrData> pEntry;
838 if (aValStr.isEmpty())
845 if(
nullptr != pStrings )
848 if (!rCell.
isEmpty() && rMatch < 0)
855 if( FormulaError::NONE != nErr )
876 if (!rCell.
isEmpty() && rMatch < 0)
882 if(
nullptr != pStrings )
890 if(
nullptr == pStrings )
897 pStrings->push_back(*pEntry);
918 sal_uInt32 nFormat = lclGetCellFormat( *
GetDocument(), rPos );
919 ScStringTokenIterator aIt( *pTokArr );
920 for (rtl_uString* pString = aIt.First(); pString && aIt.Ok(); pString = aIt.Next())
923 OUString
aStr(pString);
925 rStrColl.emplace_back(
953 bool bIsValid =
false;
971 sal_uInt32 nFormat = lclGetCellFormat( *
GetDocument(), rPos );
972 ScStringTokenIterator aIt( *pTokArr );
973 for (rtl_uString* pString = aIt.First(); pString && aIt.Ok(); pString = aIt.Next())
982 OUString
aStr(pString);
983 if (
GetDocument()->GetFormatTable()->IsNumberFormat(aStr, nFormat, fValue))
1002 bIsValid = bIsValid && nMatch >= 0;
1012 for (
const auto& rxItem : rList)
1014 InsertNew( std::unique_ptr<ScValidationData>(rxItem->Clone()) );
1025 for (
const auto& rxItem : rList)
1027 InsertNew( std::unique_ptr<ScValidationData>(rxItem->Clone(&rNewDoc)) );
1038 if( (*it)->GetKey() == nKey )
1041 OSL_FAIL(
"ScValidationDataList: Entry not found");
1048 (*it)->CompileXML();
1054 (*it)->UpdateReference(rCxt);
1060 (*it)->UpdateInsertTab(rCxt);
1066 (*it)->UpdateDeleteTab(rCxt);
1072 (*it)->UpdateMoveTab(rCxt);
static bool IsNonValueType(ScMatValType nType)
String, empty or empty path, but not value nor boolean.
Matrix data type that can store values of mixed types.
static bool IsXScriptURL(const OUString &rScriptURL)
bool IsDataValid(const OUString &rTest, const ScPatternAttr &rPattern, const ScAddress &rPos) const
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
OUString getString() const
SharedString intern(const OUString &rStr)
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.
ScDBData * findByIndex(sal_uInt16 nIndex)
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
SC_DLLPUBLIC void GetInputString(SCCOL nCol, SCROW nRow, SCTAB nTab, OUString &rString)
bool FillSelectionList(std::vector< ScTypedStrData > &rStrings, const ScAddress &rPos) const
Tries to fill the passed collection with list validation entries.
bool isLOKMobilePhone() const
const OUString & GetName(SbxNameType=SbxNameType::NONE) const
void SetInLinkUpdate(bool bSet)
bool IsDataValidCustom(const OUString &rTest, const ScPatternAttr &rPattern, const ScAddress &rPos, const CustomValidationPrivateAccess &) const
Context for reference update during shifting, moving or copying of cell ranges.
ScMatrixValue Get(SCSIZE nC, SCSIZE nR) const
: If bString the ScMatrixValue->pS may still be NULL to indicate an empty string! ...
ScValidationMode eDataMode
StarBASIC * GetBasic() const
This is very similar to ScCellValue, except that it references the original value instead of copying ...
bool HasSelectionList() const
Returns true, if the validation cell will show a selection list.
bool DoMacro(const ScAddress &rPos, const OUString &rInput, ScFormulaCell *pCell, weld::Window *pParent) const
EmbeddedObjectRef * pObject
bool IsCellValid(ScRefCellValue &rCell, const ScAddress &rPos) const
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Try NOT to use this struct.
ScValidationDataListDataType::const_iterator const_iterator
exports com.sun.star. sheet
SfxApplication * SfxGetpApp()
bool DoScript(const ScAddress &rPos, const OUString &rInput, ScFormulaCell *pCell, weld::Window *pParent) const
void UnlockTable(SCTAB nTab)
Store arbitrary cell value of any kind.
ScValidErrorStyle eErrorStyle
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt)
const EditTextObject * mpEditText
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 ...
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
ScValidationDataIsNumeric(double fVal, SvNumberFormatter *pFormatter=nullptr, sal_uInt32 nFormat=0)
static SfxViewShell * Current()
void SetInput(const OUString &rTitle, const OUString &rMsg)
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
ScFormulaCell * mpFormula
virtual ~ScValidationData() override
void commit(ScDocument &rDoc, const ScAddress &rPos) const
Set cell value at specified position in specified document.
const OUString & GetName() const
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
void init(const ScDocument &rDoc, const ScAddress &rPos)
ScValidationDataListDataType maData
ScValidationMode GetDataMode() const
void DoCalcError(ScFormulaCell *pCell) const
bool operator==(const ScFormatEntry &) const
FormulaError GetError() const
Only valid if ScMatrix methods indicate that this is no string!
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
ScValidationData * GetData(sal_uInt32 nKey)
void UpdateReference(sc::RefUpdateContext &rCxt)
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
const svl::SharedString * mpString
bool IsEqualToTokenArray(ScRefCellValue &rCell, const ScAddress &rPos, const ScTokenArray &rTokArr) const
Tests, if pCell is equal to what the passed token array represents.
#define ERRCODE_BASIC_METHOD_NOT_FOUND
ScValidationData(ScValidationMode eMode, ScConditionMode eOper, const OUString &rExpr1, const OUString &rExpr2, ScDocument &rDocument, const ScAddress &rPos, const OUString &rExprNmsp1=EMPTY_OUSTRING, const OUString &rExprNmsp2=EMPTY_OUSTRING, formula::FormulaGrammar::Grammar eGrammar1=formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::Grammar eGrammar2=formula::FormulaGrammar::GRAM_DEFAULT)
OUString ScResId(const char *pId)
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)
bool EqualEntries(const ScValidationData &r) const
const SbxObject * GetParent() const
To test numeric data text length in IsDataValidTextLen().
ErrCode CallBasic(std::u16string_view rMacro, std::u16string_view rBasicName, SbxArray *pArgs, SbxValue *pRet=nullptr)
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
css::uno::Type const & get()
void LockTable(SCTAB nTab)
void InsertNew(std::unique_ptr< ScValidationData > pNew)
bool GetErrMsg(OUString &rTitle, OUString &rMsg, ScValidErrorStyle &rStyle) const
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt)
const PropertyValue * pValues
virtual SbxDataType GetType() const override
ScValidationDataListDataType::iterator iterator
bool PutString(const OUString &)
AnnotationVector::iterator maIter
void SetError(const OUString &rTitle, const OUString &rMsg, ScValidErrorStyle eStyle)
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
SC_DLLPUBLIC bool IsReference(ScRange &rRef) const
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt)
virtual SbxVariable * Find(const OUString &, SbxClassType) override
bool IsValidReference(ScRange &rRange, const ScAddress &rPos) const
Exactly and only one valid range (no #REF!s)
bool DoError(weld::Window *pParent, const OUString &rInput, const ScAddress &rPos) const
bool IsInLinkUpdate() const
static SC_DLLPUBLIC OUString GetString(const EditTextObject &rEditText, const ScDocument *pDoc)
Retrieves string with paragraphs delimited by new lines (' ').
SfxObjectShell * GetDocumentShell() const
std::unique_ptr< ScTokenArray > CreateFlatCopiedTokenArray(sal_uInt16 nPos) const
Create a flat copy using ScTokenArray copy-ctor with shared tokens.
ScDocument * GetDocument() const
bool IsIgnoreBlank() const
SbxVariable * Get32(sal_uInt32)
SvNumberFormatter * mpFormatter
ScRangeData * FindRangeNameBySheetAndIndex(SCTAB nTab, sal_uInt16 nIndex) const
Find a named expression / range name in either global or a local scope.
void commit(ScDocument &rDoc, const ScAddress &rPos) const
Set cell value at specified position in specified document.
static OUString GetErrorString(FormulaError nErrNumber)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
bool IsDataValidTextLen(const OUString &rTest, const ScAddress &rPos, ScValidationDataIsNumeric *pDataNumeric) const
Tests, if string or numeric data has valid text length.
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...