1 diff --git sc/inc/table.hxx sc/inc/table.hxx
2 index 3c62a56..0c45c64 100644
5 @@ -702,6 +702,16 @@ private:
6 BOOL SearchAllStyle(const SvxSearchItem& rSearchItem, ScMarkData& rMark);
7 BOOL ReplaceAllStyle(const SvxSearchItem& rSearchItem, ScMarkData& rMark,
9 + bool SearchAndReplaceEmptyCells(
10 + const SvxSearchItem& rSearchItem,
11 + SCCOL& rCol, SCROW& rRow, ScMarkData& rMark,
12 + String& rUndoStr, ScDocument* pUndoDoc);
13 + bool SearchRangeForEmptyCell(const ScRange& rRange,
14 + const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
15 + String& rUndoStr, ScDocument* pUndoDoc);
16 + bool SearchRangeForAllEmptyCells(const ScRange& rRange,
17 + const SvxSearchItem& rSearchItem, ScMarkData& rMark,
18 + String& rUndoStr, ScDocument* pUndoDoc);
20 // benutzen globalen SortParam:
21 BOOL IsSorted(SCCOLROW nStart, SCCOLROW nEnd);
22 diff --git sc/source/core/data/column.cxx sc/source/core/data/column.cxx
23 index cb9dd4a..5b94923 100644
24 --- sc/source/core/data/column.cxx
25 +++ sc/source/core/data/column.cxx
26 @@ -1373,7 +1373,24 @@ void ScColumn::CopyToColumn(SCROW nRow1, SCROW nRow2, USHORT nFlags, BOOL bMarke
27 CloneCell( i, nFlags, *rColumn.pDocument, aDestPos );
30 - rColumn.Insert(pItems[i].nRow, pNew);
32 + // Special case to allow removing of cell instances. A
33 + // string cell with empty content is used to indicate an
35 + if (pNew->GetCellType() == CELLTYPE_STRING)
38 + static_cast<ScStringCell*>(pNew)->GetString(aStr);
39 + if (aStr.Len() == 0)
40 + // A string cell with empty string. Delete the cell itself.
41 + rColumn.Delete(pItems[i].nRow);
43 + // non-empty string cell
44 + rColumn.Insert(pItems[i].nRow, pNew);
47 + rColumn.Insert(pItems[i].nRow, pNew);
52 diff --git sc/source/core/data/table6.cxx sc/source/core/data/table6.cxx
53 index 994596d..8d5ec0f 100644
54 --- sc/source/core/data/table6.cxx
55 +++ sc/source/core/data/table6.cxx
57 //--------------------------------------------------------------------------
60 +using ::com::sun::star::util::SearchOptions;
62 BOOL lcl_GetTextWithBreaks( const ScEditCell& rCell, ScDocument* pDoc, String& rVal )
64 // TRUE = more than 1 paragraph
65 @@ -660,6 +662,12 @@ BOOL ScTable::SearchAndReplace(const SvxSearchItem& rSearchItem,
66 com::sun::star::util::SearchOptions aSearchOptions = rSearchItem.GetSearchOptions();
67 aSearchOptions.Locale = *ScGlobal::pLocale;
69 + if (!aSearchOptions.searchString.getLength())
71 + // Search for empty cells.
72 + return SearchAndReplaceEmptyCells(rSearchItem, rCol, rRow, rMark, rUndoStr, pUndoDoc);
75 // #107259# reflect UseAsianOptions flag in SearchOptions
76 // (use only ignore case and width if asian options are disabled).
77 // This is also done in SvxSearchDialog CommandHdl, but not in API object.
78 @@ -686,6 +694,274 @@ BOOL ScTable::SearchAndReplace(const SvxSearchItem& rSearchItem,
82 +bool ScTable::SearchAndReplaceEmptyCells(
83 + const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow, ScMarkData& rMark,
84 + String& rUndoStr, ScDocument* pUndoDoc)
86 + SCCOL nColStart, nColEnd;
87 + SCROW nRowStart, nRowEnd;
88 + GetFirstDataPos(nColStart, nRowStart);
89 + GetLastDataPos(nColEnd, nRowEnd);
91 + ScRangeList aRanges;
92 + aRanges.Append(ScRange(nColStart, nRowStart, nTab, nColEnd, nRowEnd, nTab));
94 + if (rSearchItem.GetSelection())
96 + // current selection only.
97 + if (!rMark.IsMarked() && !rMark.IsMultiMarked())
98 + // There is no selection. Bail out.
101 + ScRangeList aMarkedRanges, aNewRanges;
102 + rMark.FillRangeListWithMarks(&aMarkedRanges, true);
103 + for (ScRangePtr p = aMarkedRanges.First(); p; p = aMarkedRanges.Next())
105 + if (p->aStart.Col() > nColEnd || p->aStart.Row() > nRowEnd)
106 + // This range is outside the data area. Skip it.
109 + // Shrink the range into data area only.
110 + if (p->aStart.Col() < nColStart)
111 + p->aStart.SetCol(rCol);
112 + if (p->aStart.Row() < nRowStart)
113 + p->aStart.SetRow(rRow);
115 + if (p->aEnd.Col() > nColEnd)
116 + p->aEnd.SetCol(nColEnd);
117 + if (p->aEnd.Row() > nRowEnd)
118 + p->aEnd.SetRow(nRowEnd);
120 + aNewRanges.Append(*p);
122 + aRanges = aNewRanges;
125 + sal_uInt16 nCommand = rSearchItem.GetCommand();
126 + if (nCommand == SVX_SEARCHCMD_FIND || nCommand == SVX_SEARCHCMD_REPLACE)
128 + if (rSearchItem.GetBackward())
130 + for (ScRangePtr p = aRanges.Last(); p; p = aRanges.Prev())
132 + if (SearchRangeForEmptyCell(*p, rSearchItem, rCol, rRow, rUndoStr, pUndoDoc))
138 + for (ScRangePtr p = aRanges.First(); p; p = aRanges.Next())
140 + if (SearchRangeForEmptyCell(*p, rSearchItem, rCol, rRow, rUndoStr, pUndoDoc))
145 + else if (nCommand == SVX_SEARCHCMD_FIND_ALL || nCommand == SVX_SEARCHCMD_REPLACE_ALL)
147 + bool bFound = false;
148 + ScMarkData aNewMark(rMark);
149 + aNewMark.ResetMark();
150 + for (ScRangePtr p = aRanges.First(); p; p = aRanges.Next())
151 + bFound |= SearchRangeForAllEmptyCells(*p, rSearchItem, aNewMark, rUndoStr, pUndoDoc);
158 +bool ScTable::SearchRangeForEmptyCell(
159 + const ScRange& rRange, const SvxSearchItem& rSearchItem,
160 + SCCOL& rCol, SCROW& rRow, String& rUndoStr, ScDocument* /*pUndoDoc*/)
162 + sal_uInt16 nCmd = rSearchItem.GetCommand();
163 + if (rSearchItem.GetBackward())
166 + if (rSearchItem.GetRowDirection())
169 + SCROW nBeginRow = rRange.aEnd.Row() > rRow ? rRow : rRange.aEnd.Row();
170 + for (SCROW nRow = nBeginRow; nRow >= rRange.aStart.Row(); --nRow)
172 + SCCOL nBeginCol = rRange.aEnd.Col();
173 + if (nRow == rRow && nBeginCol >= rCol)
174 + // always start from one cell before the cursor.
175 + nBeginCol = rCol - (nCmd == SVX_SEARCHCMD_FIND ? 1 : 0);
177 + for (SCCOL nCol = nBeginCol; nCol >= rRange.aStart.Col(); --nCol)
179 + ScBaseCell* pCell = aCol[nCol].GetCell(nRow);
182 + // empty cell found.
185 + if (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE &&
186 + rSearchItem.GetReplaceString().Len())
188 + aCol[nCol].Insert(nRow, new ScStringCell(rSearchItem.GetReplaceString()));
189 + rUndoStr = String();
198 + // column direction.
199 + SCCOL nBeginCol = rRange.aEnd.Col() > rCol ? rCol : rRange.aEnd.Col();
200 + for (SCCOL nCol = nBeginCol; nCol >= rRange.aStart.Col(); --nCol)
202 + SCROW nBeginRow = rRange.aEnd.Row();
203 + if (nCol == rCol && nBeginRow >= rRow)
204 + // always start from one cell before the cursor.
205 + nBeginRow = rRow - (nCmd == SVX_SEARCHCMD_FIND ? 1 : 0);
206 + for (SCROW nRow = nBeginRow; nRow >= rRange.aStart.Row(); --nRow)
208 + ScBaseCell* pCell = aCol[nCol].GetCell(nRow);
211 + // empty cell found.
214 + if (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE &&
215 + rSearchItem.GetReplaceString().Len())
217 + aCol[nCol].Insert(nRow, new ScStringCell(rSearchItem.GetReplaceString()));
218 + rUndoStr = String();
229 + if (rSearchItem.GetRowDirection())
232 + SCROW nBeginRow = rRange.aStart.Row() < rRow ? rRow : rRange.aStart.Row();
233 + for (SCROW nRow = nBeginRow; nRow <= rRange.aEnd.Row(); ++nRow)
235 + SCCOL nBeginCol = rRange.aStart.Col();
236 + if (nRow == rRow && nBeginCol <= rCol)
237 + // always start from one cell past the cursor.
238 + nBeginCol = rCol + (nCmd == SVX_SEARCHCMD_FIND ? 1 : 0);
239 + for (SCCOL nCol = nBeginCol; nCol <= rRange.aEnd.Col(); ++nCol)
241 + ScBaseCell* pCell = aCol[nCol].GetCell(nRow);
244 + // empty cell found.
247 + if (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE &&
248 + rSearchItem.GetReplaceString().Len())
250 + aCol[nCol].Insert(nRow, new ScStringCell(rSearchItem.GetReplaceString()));
251 + rUndoStr = String();
260 + // column direction.
261 + SCCOL nBeginCol = rRange.aStart.Col() < rCol ? rCol : rRange.aStart.Col();
262 + for (SCCOL nCol = nBeginCol; nCol <= rRange.aEnd.Col(); ++nCol)
264 + SCROW nBeginRow = rRange.aStart.Row();
265 + if (nCol == rCol && nBeginRow <= rRow)
266 + // always start from one cell past the cursor.
267 + nBeginRow = rRow + (nCmd == SVX_SEARCHCMD_FIND ? 1 : 0);
268 + for (SCROW nRow = nBeginRow; nRow <= rRange.aEnd.Row(); ++nRow)
270 + ScBaseCell* pCell = aCol[nCol].GetCell(nRow);
273 + // empty cell found.
276 + if (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE &&
277 + rSearchItem.GetReplaceString().Len())
279 + aCol[nCol].Insert(nRow, new ScStringCell(rSearchItem.GetReplaceString()));
280 + rUndoStr = String();
291 +bool ScTable::SearchRangeForAllEmptyCells(
292 + const ScRange& rRange, const SvxSearchItem& rSearchItem, ScMarkData& rMark,
293 + String& rUndoStr, ScDocument* pUndoDoc)
295 + bool bFound = false;
296 + bool bReplace = (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL) &&
297 + (rSearchItem.GetReplaceString().Len() > 0);
299 + for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
301 + if (aCol[nCol].IsEmptyData())
303 + // The entire column is empty. Add the whole column and move on.
304 + rMark.SetMultiMarkArea(
305 + ScRange(nCol, rRange.aStart.Row(), nTab, nCol, rRange.aEnd.Row(), nTab));
310 + const String& rNewStr = rSearchItem.GetReplaceString();
311 + for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
313 + aCol[nCol].Insert(nRow, new ScStringCell(rNewStr));
315 + // TODO: I'm using a string cell with empty content to
316 + // trigger deletion of cell instance on undo. Maybe I
317 + // should create a new cell type for this?
318 + pUndoDoc->PutCell(nCol, nRow, nTab, new ScStringCell(String()));
320 + rUndoStr = String();
325 + for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
327 + ScBaseCell* pCell = aCol[nCol].GetCell(nRow);
330 + // empty cell found
331 + rMark.SetMultiMarkArea(ScRange(nCol, nRow, nTab));
336 + aCol[nCol].Insert(nRow, new ScStringCell(rSearchItem.GetReplaceString()));
338 + // TODO: I'm using a string cell with empty content to
339 + // trigger deletion of cell instance on undo. Maybe I
340 + // should create a new cell type for this?
341 + pUndoDoc->PutCell(nCol, nRow, nTab, new ScStringCell(String()));
353 diff --git sc/source/ui/view/tabvwsha.cxx sc/source/ui/view/tabvwsha.cxx
354 index c64698b..a7fd06d 100644
355 --- sc/source/ui/view/tabvwsha.cxx
356 +++ sc/source/ui/view/tabvwsha.cxx
357 @@ -224,8 +224,13 @@ void __EXPORT ScTabViewShell::GetState( SfxItemSet& rSet )
360 case SID_SEARCH_ITEM:
361 - rSet.Put( ScGlobal::GetSearchItem() );
363 + SvxSearchItem aItem(ScGlobal::GetSearchItem()); // make a copy.
364 + // Search on current selection if a range is marked.
365 + aItem.SetSelection(rMark.IsMarked());
370 case SID_SEARCH_OPTIONS: