summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-07-27 16:03:33 +0200
committerCaolán McNamara <caolanm@redhat.com>2016-07-28 09:23:03 +0000
commitbfa295f8a2f348c683ac28e55d5cd3c71b854f9d (patch)
tree17b23b3adab9f9b81b9372aff91a32d0471d7908 /sc
parenta2890a3fcdfcbf2447871ebc23db47864dd5b215 (diff)
handle notes on empty cells, display search results, tdf#65334 follow-up
This is a combination of 6 commits. include empty cells if notes are searched, tdf#65334 follow-up (cherry picked from commit f027c77c520adbdf8cec59e0484fc87b33cf203b) use GetCellArea() when searching for notes, tdf#65334 follow-up ... so empty cells with notes are included as last "data" position if they are below or right of the last "real" data, which GetLastDataPos() doesn't. (cherry picked from commit 09cc958dee93ad0ad2ab0d8cc9cc4c09e46c3653) do not search in empty string if there is no note, tdf#65334 follow-up (cherry picked from commit a02f7aa735c52f5d20df0e2a94cc06879cb3dfac) use GetCellArea() also in SearchAll() and ReplaceAll(), tdf#65334 follow-up (cherry picked from commit 156590e7c0bf3c81f50b3d9862961e50010ea08a) use HasCellNotes() when looping and searching for notes, tdf#65334 follow-up ... so we actually find all if on empty cells. (cherry picked from commit d93284f65cf14fdf5e2520b474eb7383ca1d99e4) display the SearchAll() and ReplaceAll() results for notes, tdf#65334 related (cherry picked from commit 4f719263ae8dc44eabfba4654f9dbed92a9c5360) 9bb7464033736e7e7fa24e635ef1a3d39626002b 6c347b5bccd4ffd6a43a80e9d73a0b5fcf82926b 50bfeee96e57010455bbb9e8be4312a39d392411 e504ce7df2a17877eddf21cf309990a2a8b692ba b9ff40b26526efdf242db2ef1804e54611f16b0e Change-Id: Ib67b9745ffff730b209df2b82dc7e46fc4774900 Reviewed-on: https://gerrit.libreoffice.org/27603 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/table6.cxx81
-rw-r--r--sc/source/ui/dialogs/searchresults.cxx55
-rw-r--r--sc/source/ui/inc/searchresults.hxx2
-rw-r--r--sc/source/ui/view/viewfun2.cxx3
4 files changed, 112 insertions, 29 deletions
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index b5a4499fb7fc..e7e7caf244c7 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -68,12 +68,22 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, SCROW nRo
if (!bDoSearch)
return false;
- aCell = aCol[nCol].GetCellValue(nRow);
- if (aCell.isEmpty())
- return false;
+ ScPostIt* pNote;
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ {
+ pNote = aCol[nCol].GetCellNote(nRow);
+ if (!pNote)
+ return false;
+ }
+ else
+ {
+ aCell = aCol[nCol].GetCellValue(nRow);
+ if (aCell.isEmpty())
+ return false;
+ pNote = nullptr;
+ }
bool bMultiLine = false;
- ScPostIt* pNote = nullptr;
CellType eCellType = aCell.meType;
switch (rSearchItem.GetCellType())
{
@@ -105,7 +115,6 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, SCROW nRo
break;
case SvxSearchCellType::NOTE:
{
- pNote = aCol[nCol].GetCellNote(nRow);
if (pNote)
{
aString = pNote->GetText();
@@ -300,7 +309,10 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
{
SCCOL nLastCol;
SCROW nLastRow;
- GetLastDataPos(nLastCol, nLastRow);
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ GetCellArea( nLastCol, nLastRow);
+ else
+ GetLastDataPos(nLastCol, nLastRow);
return Search(rSearchItem, rCol, rRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc);
}
@@ -315,6 +327,7 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
SCROW nRow = rRow;
bool bSkipFiltered = !rSearchItem.IsSearchFiltered();
+ bool bSearchNotes = (rSearchItem.GetCellType() == SvxSearchCellType::NOTE);
if (!bAll && rSearchItem.GetBackward())
{
SCROW nLastNonFilteredRow = MAXROW + 1;
@@ -338,7 +351,12 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
{
nCol--;
if ((SCsCOL)nCol >= 0)
- bIsEmpty = aCol[nCol].IsEmptyData();
+ {
+ if (bSearchNotes)
+ bIsEmpty = !aCol[nCol].HasCellNotes();
+ else
+ bIsEmpty = aCol[nCol].IsEmptyData();
+ }
else
bIsEmpty = true;
}
@@ -365,8 +383,16 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
if (!bFound)
{
- if (!aCol[nCol].GetPrevDataPos(nRow))
- nRow = -1;
+ if (bSearchNotes)
+ {
+ /* TODO: can we look for the previous cell note instead? */
+ --nRow;
+ }
+ else
+ {
+ if (!aCol[nCol].GetPrevDataPos(nRow))
+ nRow = -1;
+ }
}
}
if (!bFound)
@@ -379,7 +405,12 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
{
nCol--;
if ((SCsCOL)nCol >= 0)
- bIsEmpty = aCol[nCol].IsEmptyData();
+ {
+ if (bSearchNotes)
+ bIsEmpty = !aCol[nCol].HasCellNotes();
+ else
+ bIsEmpty = aCol[nCol].IsEmptyData();
+ }
else
bIsEmpty = true;
}
@@ -405,7 +436,9 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
if (!bFound)
{
nCol++;
- while ((nCol <= nLastCol) && aCol[nCol].IsEmptyData()) nCol++;
+ while ((nCol <= nLastCol) &&
+ (bSearchNotes ? !aCol[nCol].HasCellNotes() : aCol[nCol].IsEmptyData()))
+ nCol++;
}
}
if (!bFound)
@@ -428,8 +461,16 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
if (!bFound)
{
- if (!aCol[nCol].GetNextDataPos(nRow))
- nRow = MAXROW + 1;
+ if (bSearchNotes)
+ {
+ /* TODO: can we look for the next cell note instead? */
+ ++nRow;
+ }
+ else
+ {
+ if (!aCol[nCol].GetNextDataPos(nRow))
+ nRow = MAXROW + 1;
+ }
}
}
if (!bFound)
@@ -438,7 +479,9 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
nRow = 0;
nLastNonFilteredRow = -1;
nCol++;
- while ((nCol <= nLastCol) && aCol[nCol].IsEmptyData()) nCol++;
+ while ((nCol <= nLastCol) &&
+ (bSearchNotes ? !aCol[nCol].HasCellNotes() : aCol[nCol].IsEmptyData()))
+ nCol++;
}
}
}
@@ -461,7 +504,10 @@ bool ScTable::SearchAll(const SvxSearchItem& rSearchItem, const ScMarkData& rMar
SCCOL nLastCol;
SCROW nLastRow;
- GetLastDataPos(nLastCol, nLastRow);
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ GetCellArea( nLastCol, nLastRow);
+ else
+ GetLastDataPos(nLastCol, nLastRow);
do
{
@@ -520,7 +566,10 @@ bool ScTable::ReplaceAll(
SCCOL nLastCol;
SCROW nLastRow;
- GetLastDataPos(nLastCol, nLastRow);
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ GetCellArea( nLastCol, nLastRow);
+ else
+ GetLastDataPos(nLastCol, nLastRow);
bool bEverFound = false;
while (true)
diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx
index 225fb2f0318b..c6e747084a6f 100644
--- a/sc/source/ui/dialogs/searchresults.cxx
+++ b/sc/source/ui/dialogs/searchresults.cxx
@@ -50,24 +50,57 @@ void SearchResultsDlg::dispose()
ModelessDialog::dispose();
}
-void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges )
+void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges, bool bCellNotes )
{
mpList->Clear();
mpList->SetUpdateMode(false);
std::vector<OUString> aTabNames = pDoc->GetAllTableNames();
SCTAB nTabCount = aTabNames.size();
- for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
+ if (bCellNotes)
{
- ScCellIterator aIter(pDoc, *rMatchedRanges[i]);
- for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
+ for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
{
- ScAddress aPos = aIter.GetPos();
- if (aPos.Tab() >= nTabCount)
- // Out-of-bound sheet index.
- continue;
-
- OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention());
- mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos));
+ /* TODO: a CellNotes iterator would come handy and migt speed
+ * things up a little, though we only loop through the
+ * search/replace result positions here. */
+ ScRange aRange( *rMatchedRanges[i] );
+ // Bear in mind that mostly the range is one address position
+ // or a column or a row joined.
+ ScAddress aPos( aRange.aStart );
+ for ( ; aPos.Tab() <= aRange.aEnd.Tab(); aPos.IncTab())
+ {
+ if (aPos.Tab() >= nTabCount)
+ break; // can this even happen? we just searched on existing sheets ...
+ for (aPos.SetCol( aRange.aStart.Col()); aPos.Col() <= aRange.aEnd.Col(); aPos.IncCol())
+ {
+ for (aPos.SetRow( aRange.aStart.Row()); aPos.Row() <= aRange.aEnd.Row(); aPos.IncRow())
+ {
+ const ScPostIt* pNote = pDoc->GetNote( aPos);
+ if (pNote)
+ {
+ OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention());
+ mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pNote->GetText());
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
+ {
+ ScCellIterator aIter(pDoc, *rMatchedRanges[i]);
+ for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
+ {
+ ScAddress aPos = aIter.GetPos();
+ if (aPos.Tab() >= nTabCount)
+ // Out-of-bound sheet index.
+ continue;
+
+ OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention());
+ mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos));
+ }
}
}
mpList->SetUpdateMode(true);
diff --git a/sc/source/ui/inc/searchresults.hxx b/sc/source/ui/inc/searchresults.hxx
index 8143c48d56b6..776a23f66df1 100644
--- a/sc/source/ui/inc/searchresults.hxx
+++ b/sc/source/ui/inc/searchresults.hxx
@@ -32,7 +32,7 @@ public:
virtual ~SearchResultsDlg();
virtual void dispose() override;
- void FillResults( ScDocument* pDoc, const ScRangeList& rMatchedRanges );
+ void FillResults( ScDocument* pDoc, const ScRangeList& rMatchedRanges, bool bCellNotes );
virtual bool Close() override;
};
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index d0b3cad53cd5..fb6a6ebecbeb 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -1742,7 +1742,8 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem,
{
sc::SearchResultsDlg* pDlg = static_cast<sc::SearchResultsDlg*>(pWnd->GetWindow());
if (pDlg)
- pDlg->FillResults(&rDoc, aMatchedRanges);
+ pDlg->FillResults(&rDoc, aMatchedRanges,
+ pSearchItem->GetCellType() == SvxSearchCellType::NOTE);
}
}