tdf#142214: autoinput: remove search/entry count limits

Change-Id: Ib41f7c04b9a3802982105cbbfef3ae638bdb286f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115345
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115545
Tested-by: Jenkins
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 56791cf..197dc17 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -541,7 +541,7 @@ public:
        sc::ColumnBlockConstPosition& rBlockPos, SCROW nStartRow, SCROW nEndRow,
        ScFilterEntries& rFilterEntries, bool bFiltering );

    bool GetDataEntries( SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit ) const;
    bool GetDataEntries( SCROW nRow, std::set<ScTypedStrData>& rStrings) const;

    void UpdateInsertTabAbs(SCTAB nNewPos);
    bool    TestTabRefAbs(SCTAB nTable) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index f90e74e..d314ea6 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2089,7 +2089,7 @@ public:
                                            ScFilterEntries& rFilterEntries );

    void              GetDataEntries( SCCOL nCol, SCROW nRow, SCTAB nTab,
                                      std::vector<ScTypedStrData>& rStrings, bool bLimit = false );
                                      std::vector<ScTypedStrData>& rStrings, bool bValidation = false );
    void              GetFormulaEntries( ScTypedCaseStrSet& rStrings );

    bool               HasAutoFilter( SCCOL nCol, SCROW nRow, SCTAB nTab );
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 416cbb5..2436b0c 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -961,7 +961,7 @@ public:
    void GetFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries );
    void GetFilteredFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries, bool bFiltering );
    [[nodiscard]]
    bool GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit);
    bool GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings);

    bool        HasColHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const;
    bool        HasRowHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const;
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 51bc475..de6870a 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2697,14 +2697,8 @@ public:
}

// GetDataEntries - Strings from continuous Section around nRow

// DATENT_MAX      - max. number of entries in list for auto entry
// DATENT_SEARCH   - max. number of cells that get transparent - new: only count Strings
#define DATENT_MAX      200
#define DATENT_SEARCH   2000

bool ScColumn::GetDataEntries(
    SCROW nStartRow, std::set<ScTypedStrData>& rStrings, bool bLimit ) const
    SCROW nStartRow, std::set<ScTypedStrData>& rStrings) const
{
    // Start at the specified row position, and collect all string values
    // going upward and downward directions in parallel. The start position
@@ -2722,44 +2716,30 @@ bool ScColumn::GetDataEntries(
        bMoveDown = aItrDown.next(); // Find the next string cell position.

    bool bFound = false;
    size_t nCellsSearched = 0;
    while (bMoveUp || bMoveDown)
    while (bMoveUp)
    {
        if (bMoveUp)
        // Get the current string and move up.
        OUString aStr = aItrUp.get();
        if (!aStr.isEmpty())
        {
            // Get the current string and move up.
            OUString aStr = aItrUp.get();
            if (!aStr.isEmpty())
            {
                bool bInserted = rStrings.insert(ScTypedStrData(aStr)).second;
                if (bInserted && bLimit && rStrings.size() >= DATENT_MAX)
                    return true; // Maximum reached
            if (rStrings.insert(ScTypedStrData(aStr)).second)
                bFound = true;
            }

            if (bLimit && ++nCellsSearched >= DATENT_SEARCH)
                return bFound; // max search cell count reached.

            bMoveUp = aItrUp.prev();
        }

        if (bMoveDown)
        bMoveUp = aItrUp.prev();
    }

    while (bMoveDown)
    {
        // Get the current string and move down.
        OUString aStr = aItrDown.get();
        if (!aStr.isEmpty())
        {
            // Get the current string and move down.
            OUString aStr = aItrDown.get();
            if (!aStr.isEmpty())
            {
                bool bInserted = rStrings.insert(ScTypedStrData(aStr)).second;
                if (bInserted && bLimit && rStrings.size() >= DATENT_MAX)
                    return true; // Maximum reached
            if (rStrings.insert(ScTypedStrData(aStr)).second)
                bFound = true;
            }

            if (bLimit && ++nCellsSearched >= DATENT_SEARCH)
                return bFound; // max search cell count reached.

            bMoveDown = aItrDown.next();
        }

        bMoveDown = aItrDown.next();
    }

    return bFound;
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index b47c03c..8de06d1 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1616,12 +1616,12 @@ void ScDocument::GetFilterEntriesArea(
 */
void ScDocument::GetDataEntries(
    SCCOL nCol, SCROW nRow, SCTAB nTab,
    std::vector<ScTypedStrData>& rStrings, bool bLimit )
    std::vector<ScTypedStrData>& rStrings, bool bValidation )
{
    if( !bLimit )
    if( bValidation )
    {
        /*  Try to generate the list from list validation. This part is skipped,
            if bLimit==true, because in that case this function is called to get
            if bValidation==false, because in that case this function is called to get
            cell values for auto completion on input. */
        sal_uInt32 nValidation = GetAttr( nCol, nRow, nTab, ATTR_VALIDDATA )->GetValue();
        if( nValidation )
@@ -1644,7 +1644,7 @@ void ScDocument::GetDataEntries(
        return;

    std::set<ScTypedStrData> aStrings;
    if (maTabs[nTab]->GetDataEntries(nCol, nRow, aStrings, bLimit))
    if (maTabs[nTab]->GetDataEntries(nCol, nRow, aStrings))
    {
        rStrings.insert(rStrings.end(), aStrings.begin(), aStrings.end());
        sortAndRemoveDuplicates(rStrings, true/*bCaseSens*/);
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 54c0850..552abe5b0 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -3570,9 +3570,9 @@ void ScTable::GetFilteredFilterEntries(
    }
}

bool ScTable::GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit)
bool ScTable::GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings)
{
    return aCol[nCol].GetDataEntries( nRow, rStrings, bLimit );
    return aCol[nCol].GetDataEntries( nRow, rStrings);
}

sal_uLong ScTable::GetCellCount() const
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 3082cdb..2ef4df7 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -1941,7 +1941,7 @@ void ScInputHandler::GetColData()

    std::vector<ScTypedStrData> aEntries;
    rDoc.GetDataEntries(
        aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aEntries, true);
        aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aEntries);
    if (!aEntries.empty())
        pColumnData->insert(aEntries.begin(), aEntries.end());

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index c6c1f52..92b3e31 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -1166,7 +1166,7 @@ void ScGridWindow::LaunchDataSelectMenu( SCCOL nCol, SCROW nRow )
    bool bEmpty = false;
    std::vector<ScTypedStrData> aStrings; // case sensitive
    // Fill List
    rDoc.GetDataEntries(nCol, nRow, nTab, aStrings);
    rDoc.GetDataEntries(nCol, nRow, nTab, aStrings, true /* bValidation */);
    if (aStrings.empty())
        bEmpty = true;