xref: /aoo4110/main/sc/source/core/data/table6.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 // INCLUDE ---------------------------------------------------------------
28 
29 #include <com/sun/star/i18n/TransliterationModules.hpp>
30 
31 #include <unotools/textsearch.hxx>
32 #include <svl/srchitem.hxx>
33 #include <editeng/editobj.hxx>
34 
35 #include "table.hxx"
36 #include "collect.hxx"
37 #include "cell.hxx"
38 #include "document.hxx"
39 #include "stlpool.hxx"
40 #include "markdata.hxx"
41 #include "editutil.hxx"
42 #include "detfunc.hxx"
43 #include "postit.hxx"
44 
45 //--------------------------------------------------------------------------
46 
47 
lcl_GetTextWithBreaks(const ScEditCell & rCell,ScDocument * pDoc,String & rVal)48 sal_Bool lcl_GetTextWithBreaks( const ScEditCell& rCell, ScDocument* pDoc, String& rVal )
49 {
50 	//	sal_True = more than 1 paragraph
51 
52 	const EditTextObject* pData = NULL;
53 	rCell.GetData( pData );
54 	EditEngine& rEngine = pDoc->GetEditEngine();
55 	rEngine.SetText( *pData );
56 	rVal = rEngine.GetText( LINEEND_LF );
57 	return ( rEngine.GetParagraphCount() > 1 );
58 }
59 
SearchCell(const SvxSearchItem & rSearchItem,SCCOL nCol,SCROW nRow,const ScMarkData & rMark,String & rUndoStr,ScDocument * pUndoDoc)60 sal_Bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, SCROW nRow,
61 							const ScMarkData& rMark, String& rUndoStr, ScDocument* pUndoDoc)
62 {
63 	sal_Bool	bFound = sal_False;
64 	sal_Bool 	bDoSearch = sal_True;
65 	sal_Bool	bDoBack = rSearchItem.GetBackward();
66 
67 	String	aString;
68 	ScBaseCell* pCell;
69 	if (rSearchItem.GetSelection())
70 		bDoSearch = rMark.IsCellMarked(nCol, nRow);
71 	if ( bDoSearch && ((pCell = aCol[nCol].GetCell( nRow )) != NULL) )
72 	{
73 		sal_Bool bMultiLine = sal_False;
74 		CellType eCellType = pCell->GetCellType();
75 		switch (rSearchItem.GetCellType())
76 		{
77 			case SVX_SEARCHIN_FORMULA:
78 			{
79 				if ( eCellType == CELLTYPE_FORMULA )
80                     ((ScFormulaCell*)pCell)->GetFormula( aString,
81                        formula::FormulaGrammar::GRAM_NATIVE_UI);
82 				else if ( eCellType == CELLTYPE_EDIT )
83 					bMultiLine = lcl_GetTextWithBreaks(
84 						*(const ScEditCell*)pCell, pDocument, aString );
85 				else
86 					aCol[nCol].GetInputString( nRow, aString );
87 			}
88 			break;
89 			case SVX_SEARCHIN_VALUE:
90 				if ( eCellType == CELLTYPE_EDIT )
91 					bMultiLine = lcl_GetTextWithBreaks(
92 						*(const ScEditCell*)pCell, pDocument, aString );
93 				else
94 					aCol[nCol].GetInputString( nRow, aString );
95 				break;
96 			case SVX_SEARCHIN_NOTE:
97 				{
98                     if(const ScPostIt* pNote = pCell->GetNote())
99 				    {
100                         aString = pNote->GetText();
101                         bMultiLine = pNote->HasMultiLineText();
102 				    }
103 				}
104 				break;
105 			default:
106 				break;
107 		}
108 		xub_StrLen nStart = 0;
109 		xub_StrLen nEnd = aString.Len();
110         ::com::sun::star::util::SearchResult aSearchResult;
111 		if (pSearchText)
112 		{
113 			if ( bDoBack )
114 			{
115 				xub_StrLen nTemp=nStart; nStart=nEnd; nEnd=nTemp;
116 				bFound = (sal_Bool)(pSearchText->SearchBkwrd(aString, &nStart, &nEnd, &aSearchResult));
117 				// change results to definition before 614:
118 				--nEnd;
119 			}
120 			else
121 			{
122 				bFound = (sal_Bool)(pSearchText->SearchFrwrd(aString, &nStart, &nEnd, &aSearchResult));
123 				// change results to definition before 614:
124 				--nEnd;
125 			}
126 
127 			if (bFound && rSearchItem.GetWordOnly())
128 				bFound = (nStart == 0 && nEnd == aString.Len() - 1);
129 		}
130 		else
131 		{
132 			DBG_ERROR("pSearchText == NULL");
133 			return bFound;
134 		}
135 
136 		sal_uInt8 cMatrixFlag = MM_NONE;
137 		if ( bFound &&
138 			( (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE)
139 			||(rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL) ) &&
140 				// #60558# Matrix nicht zerreissen, nur Matrixformel ersetzen
141 				!( (eCellType == CELLTYPE_FORMULA &&
142 				((cMatrixFlag = ((ScFormulaCell*)pCell)->GetMatrixFlag()) == MM_REFERENCE))
143 				// kein UndoDoc => Matrix nicht wiederherstellbar => nicht ersetzen
144 				|| (cMatrixFlag != MM_NONE && !pUndoDoc) )
145 			)
146 		{
147 			if ( cMatrixFlag == MM_NONE && rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE )
148 				rUndoStr = aString;
149 			else if (pUndoDoc)
150 			{
151 				ScAddress aAdr( nCol, nRow, nTab );
152                 ScBaseCell* pUndoCell = pCell->CloneWithoutNote( *pUndoDoc );
153 				pUndoDoc->PutCell( aAdr, pUndoCell);
154 			}
155 			sal_Bool bRepeat = !rSearchItem.GetWordOnly();
156 			do
157 			{
158 				//	wenn der gefundene Text leer ist, nicht weitersuchen,
159 				//	sonst wuerde man nie mehr aufhoeren (#35410#)
160 				if ( nEnd < nStart || nEnd == STRING_MAXLEN )
161 					bRepeat = sal_False;
162 
163 				String sReplStr = rSearchItem.GetReplaceString();
164 				if (rSearchItem.GetRegExp())
165 				{
166 					String sFndStr = aString.Copy(nStart, nEnd-nStart+1);
167                     pSearchText->ReplaceBackReferences( sReplStr, aString, aSearchResult );
168 					aString.Erase(nStart, nEnd-nStart+1);
169 					aString.Insert(sReplStr, nStart);
170 				}
171 				else
172 				{
173 					aString.Erase(nStart, nEnd - nStart + 1);
174 					aString.Insert(rSearchItem.GetReplaceString(), nStart);
175 				}
176 
177 						//	Indizes anpassen
178 				if (bDoBack)
179 				{
180 					nEnd = nStart;
181 					nStart = 0;
182 				}
183 				else
184 				{
185                     nStart = sal::static_int_cast<xub_StrLen>( nStart + sReplStr.Len() );
186 					nEnd = aString.Len();
187 				}
188 
189 						//	weitersuchen ?
190 				if (bRepeat)
191 				{
192 					if ( rSearchItem.GetCommand() != SVX_SEARCHCMD_REPLACE_ALL || nStart >= nEnd )
193 						bRepeat = sal_False;
194 					else if (bDoBack)
195 					{
196 						xub_StrLen nTemp=nStart; nStart=nEnd; nEnd=nTemp;
197 						bRepeat = ((sal_Bool)(pSearchText->SearchBkwrd(aString, &nStart, &nEnd, &aSearchResult)));
198 						// change results to definition before 614:
199 						--nEnd;
200 					}
201 					else
202 					{
203 						bRepeat = ((sal_Bool)(pSearchText->SearchFrwrd(aString, &nStart, &nEnd, &aSearchResult)));
204 						// change results to definition before 614:
205 						--nEnd;
206 					}
207 				}
208 			}
209 			while (bRepeat);
210 			if (rSearchItem.GetCellType() == SVX_SEARCHIN_NOTE)
211 			{
212                 // NB: rich text format is lost.
213                 // This is also true of Cells.
214                 if( ScPostIt* pNote = pCell->GetNote() )
215                     pNote->SetText( ScAddress( nCol, nRow, nTab ), aString );
216 			}
217 			else if ( cMatrixFlag != MM_NONE )
218 			{	// #60558# Matrix nicht zerreissen
219 				if ( aString.Len() > 2 )
220 				{	// {} raus, erst hier damit auch "{=" durch "{=..." ersetzt werden kann
221 					if ( aString.GetChar( aString.Len()-1 ) == '}' )
222 						aString.Erase( aString.Len()-1, 1 );
223 					if ( aString.GetChar(0) == '{' )
224 						aString.Erase( 0, 1 );
225 				}
226 				ScAddress aAdr( nCol, nRow, nTab );
227 				ScFormulaCell* pFCell = new ScFormulaCell( pDocument, aAdr,
228 					aString,formula::FormulaGrammar::GRAM_NATIVE_UI, cMatrixFlag );
229                 SCCOL nMatCols;
230                 SCROW nMatRows;
231 				((ScFormulaCell*)pCell)->GetMatColsRows( nMatCols, nMatRows );
232 				pFCell->SetMatColsRows( nMatCols, nMatRows );
233 				aCol[nCol].Insert( nRow, pFCell );
234 			}
235 			else if ( bMultiLine && aString.Search('\n') != STRING_NOTFOUND )
236 				PutCell( nCol, nRow, new ScEditCell( aString, pDocument ) );
237 			else
238 				aCol[nCol].SetString(nRow, nTab, aString);
239 			// pCell is invalid now (deleted)
240 		}
241 	}
242 	return bFound;
243 }
244 
Search(const SvxSearchItem & rSearchItem,SCCOL & rCol,SCROW & rRow,const ScMarkData & rMark,String & rUndoStr,ScDocument * pUndoDoc)245 sal_Bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
246 						const ScMarkData& rMark, String& rUndoStr, ScDocument* pUndoDoc)
247 {
248 	sal_Bool bFound = sal_False;
249 	sal_Bool bAll =  (rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND_ALL)
250 			   ||(rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL);
251 	SCCOL nCol = rCol;
252 	SCROW nRow = rRow;
253 	SCCOL nLastCol;
254 	SCROW nLastRow;
255 	GetLastDataPos(nLastCol, nLastRow);
256 	if (!bAll && rSearchItem.GetBackward())
257 	{
258 		nCol = Min(nCol, (SCCOL)(nLastCol + 1));
259 		nRow = Min(nRow, (SCROW)(nLastRow + 1));
260 		if (rSearchItem.GetRowDirection())
261 		{
262 			nCol--;
263 			while (!bFound && ((SCsROW)nRow >= 0))
264 			{
265 				while (!bFound && ((SCsCOL)nCol >= 0))
266 				{
267 					bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
268 					if (!bFound)
269 					{
270 						sal_Bool bIsEmpty;
271 						do
272 						{
273 							nCol--;
274 							if ((SCsCOL)nCol >= 0)
275 								bIsEmpty = aCol[nCol].IsEmptyData();
276 							else
277 								bIsEmpty = sal_True;
278 						}
279 						while (((SCsCOL)nCol >= 0) && bIsEmpty);
280 					}
281 				}
282 				if (!bFound)
283 				{
284 					nCol = nLastCol;
285 					nRow--;
286 				}
287 			}
288 		}
289 		else
290 		{
291 			nRow--;
292 			while (!bFound && ((SCsCOL)nCol >= 0))
293 			{
294 				while (!bFound && ((SCsROW)nRow >= 0))
295 				{
296 					bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
297 					if (!bFound)
298 					{
299 						 if (!aCol[nCol].GetPrevDataPos(nRow))
300 							nRow = -1;
301 					}
302 				}
303 				if (!bFound)
304 				{
305 					sal_Bool bIsEmpty;
306 					nRow = nLastRow;
307 					do
308 					{
309 						nCol--;
310 						if ((SCsCOL)nCol >= 0)
311 							bIsEmpty = aCol[nCol].IsEmptyData();
312 						else
313 							bIsEmpty = sal_True;
314 					}
315 					while (((SCsCOL)nCol >= 0) && bIsEmpty);
316 				}
317 			}
318 		}
319 	}
320 	else
321 	{
322 		if (!bAll && rSearchItem.GetRowDirection())
323 		{
324 			nCol++;
325 			while (!bFound && (nRow <= nLastRow))
326 			{
327 				while (!bFound && (nCol <= nLastCol))
328 				{
329 					bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
330 					if (!bFound)
331 					{
332 						nCol++;
333 						while ((nCol <= nLastCol) && aCol[nCol].IsEmptyData()) nCol++;
334 					}
335 				}
336 				if (!bFound)
337 				{
338 					nCol = 0;
339 					nRow++;
340 				}
341 			}
342 		}
343 		else
344 		{
345 			nRow++;
346 			while (!bFound && (nCol <= nLastCol))
347 			{
348 				while (!bFound && (nRow <= nLastRow))
349 				{
350 					bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
351 					if (!bFound)
352 					{
353 						 if (!aCol[nCol].GetNextDataPos(nRow))
354 							nRow = MAXROW + 1;
355 					}
356 				}
357 				if (!bFound)
358 				{
359 					nRow = 0;
360 					nCol++;
361 					while ((nCol <= nLastCol) && aCol[nCol].IsEmptyData()) nCol++;
362 				}
363 			}
364 		}
365 	}
366 	if (bFound)
367 	{
368 		rCol = nCol;
369 		rRow = nRow;
370 	}
371 	return bFound;
372 }
373 
SearchAll(const SvxSearchItem & rSearchItem,ScMarkData & rMark,String & rUndoStr,ScDocument * pUndoDoc)374 sal_Bool ScTable::SearchAll(const SvxSearchItem& rSearchItem, ScMarkData& rMark,
375 						String& rUndoStr, ScDocument* pUndoDoc)
376 {
377 	sal_Bool bFound = sal_True;
378 	SCCOL nCol = 0;
379 	SCROW nRow = -1;
380 
381 	ScMarkData aNewMark( rMark );	// Tabellen-Markierungen kopieren
382 	aNewMark.ResetMark();
383 	do
384 	{
385 		bFound = Search(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
386 		if (bFound)
387 			aNewMark.SetMultiMarkArea( ScRange( nCol, nRow, nTab ) );
388 	}
389 	while (bFound);
390 
391 	rMark = aNewMark;		//	Markierung kopieren
392 							//!	pro Tabelle
393 
394 	return (aNewMark.IsMultiMarked());
395 }
396 
Replace(const SvxSearchItem & rSearchItem,SCCOL & rCol,SCROW & rRow,const ScMarkData & rMark,String & rUndoStr,ScDocument * pUndoDoc)397 sal_Bool ScTable::Replace(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
398 						const ScMarkData& rMark, String& rUndoStr, ScDocument* pUndoDoc)
399 {
400 	sal_Bool bFound = sal_False;
401 	SCCOL nCol = rCol;
402 	SCROW nRow = rRow;
403 	if (rSearchItem.GetBackward())
404 	{
405 		if (rSearchItem.GetRowDirection())
406 			nCol += 1;
407 		else
408 			nRow += 1;
409 	}
410 	else
411 	{
412 		if (rSearchItem.GetRowDirection())
413 			nCol -= 1;
414 		else
415 			nRow -= 1;
416 	}
417 	bFound = Search(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
418 	if (bFound)
419 	{
420 		rCol = nCol;
421 		rRow = nRow;
422 	}
423 	return bFound;
424 }
425 
ReplaceAll(const SvxSearchItem & rSearchItem,ScMarkData & rMark,String & rUndoStr,ScDocument * pUndoDoc)426 sal_Bool ScTable::ReplaceAll(const SvxSearchItem& rSearchItem, ScMarkData& rMark,
427 							String& rUndoStr, ScDocument* pUndoDoc)
428 {
429 	sal_Bool bOldDouble = ScColumn::bDoubleAlloc;		// sollte immer sal_False sein?
430 	DBG_ASSERT(!bOldDouble,"bDoubleAlloc ???");
431 	ScColumn::bDoubleAlloc = sal_True;					// fuer Undo-Doc
432 
433 	sal_Bool bFound = sal_True;
434 	SCCOL nCol = 0;
435 	SCROW nRow = -1;
436 
437 	ScMarkData aNewMark( rMark );	// Tabellen-Markierungen kopieren
438 	aNewMark.ResetMark();
439 	do
440 	{
441 		bFound = Search(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
442 		if (bFound)
443 			aNewMark.SetMultiMarkArea( ScRange( nCol, nRow, nTab ) );
444 	}
445 	while (bFound);
446 
447 	ScColumn::bDoubleAlloc = bOldDouble;
448 
449 	rMark = aNewMark;		//	Markierung kopieren
450 							//!	pro Tabelle
451 
452 	return (aNewMark.IsMultiMarked());
453 }
454 
SearchStyle(const SvxSearchItem & rSearchItem,SCCOL & rCol,SCROW & rRow,ScMarkData & rMark)455 sal_Bool ScTable::SearchStyle(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
456 							ScMarkData& rMark)
457 {
458 	const ScStyleSheet* pSearchStyle = (const ScStyleSheet*)
459 										pDocument->GetStyleSheetPool()->Find(
460 										rSearchItem.GetSearchString(), SFX_STYLE_FAMILY_PARA );
461 
462 	SCsCOL nCol = rCol;
463 	SCsROW nRow = rRow;
464 	sal_Bool bFound = sal_False;
465 
466 	sal_Bool bSelect = rSearchItem.GetSelection();
467 	sal_Bool bRows = rSearchItem.GetRowDirection();
468 	sal_Bool bBack = rSearchItem.GetBackward();
469 	short nAdd = bBack ? -1 : 1;
470 
471 	if (bRows)										// zeilenweise
472 	{
473 		nRow += nAdd;
474 		do
475 		{
476 			SCsROW nNextRow = aCol[nCol].SearchStyle( nRow, pSearchStyle, bBack, bSelect, rMark );
477 			if (!ValidRow(nNextRow))
478 			{
479 				nRow = bBack ? MAXROW : 0;
480                 nCol = sal::static_int_cast<SCsCOL>( nCol + nAdd );
481 			}
482 			else
483 			{
484 				nRow = nNextRow;
485 				bFound = sal_True;
486 			}
487 		}
488 		while (!bFound && ValidCol(nCol));
489 	}
490 	else											// spaltenweise
491 	{
492 		SCsROW nNextRows[MAXCOLCOUNT];
493 		SCsCOL i;
494 		for (i=0; i<=MAXCOL; i++)
495 		{
496 			SCsROW nSRow = nRow;
497 			if (bBack)	{ if (i>=nCol) --nSRow; }
498 			else		{ if (i<=nCol) ++nSRow;	}
499 			nNextRows[i] = aCol[i].SearchStyle( nSRow, pSearchStyle, bBack, bSelect, rMark );
500 		}
501 		if (bBack)							// rueckwaerts
502 		{
503 			nRow = -1;
504 			for (i=MAXCOL; i>=0; i--)
505 				if (nNextRows[i]>nRow)
506 				{
507 					nCol = i;
508 					nRow = nNextRows[i];
509 					bFound = sal_True;
510 				}
511 		}
512 		else								// vorwaerts
513 		{
514 			nRow = MAXROW+1;
515 			for (i=0; i<=MAXCOL; i++)
516 				if (nNextRows[i]<nRow)
517 				{
518 					nCol = i;
519 					nRow = nNextRows[i];
520 					bFound = sal_True;
521 				}
522 		}
523 	}
524 
525 	if (bFound)
526 	{
527 		rCol = (SCCOL) nCol;
528 		rRow = (SCROW) nRow;
529 	}
530 	return bFound;
531 }
532 
533 //!		einzelnes Pattern fuer Undo zurueckgeben
534 
ReplaceStyle(const SvxSearchItem & rSearchItem,SCCOL & rCol,SCROW & rRow,ScMarkData & rMark,sal_Bool bIsUndo)535 sal_Bool ScTable::ReplaceStyle(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
536 						   ScMarkData& rMark, sal_Bool bIsUndo)
537 {
538 	sal_Bool bRet;
539 	if (bIsUndo)
540 		bRet = sal_True;
541 	else
542 		bRet = SearchStyle(rSearchItem, rCol, rRow, rMark);
543 	if (bRet)
544 	{
545 		const ScStyleSheet* pReplaceStyle = (const ScStyleSheet*)
546 										pDocument->GetStyleSheetPool()->Find(
547 										rSearchItem.GetReplaceString(), SFX_STYLE_FAMILY_PARA );
548 
549 		if (pReplaceStyle)
550 			ApplyStyle( rCol, rRow, *pReplaceStyle );
551 		else
552 		{
553 			DBG_ERROR("pReplaceStyle==0");
554 		}
555 	}
556 
557 	return bRet;
558 }
559 
SearchAllStyle(const SvxSearchItem & rSearchItem,ScMarkData & rMark)560 sal_Bool ScTable::SearchAllStyle(const SvxSearchItem& rSearchItem, ScMarkData& rMark)
561 {
562 	const ScStyleSheet* pSearchStyle = (const ScStyleSheet*)
563 										pDocument->GetStyleSheetPool()->Find(
564 										rSearchItem.GetSearchString(), SFX_STYLE_FAMILY_PARA );
565 	sal_Bool bSelect = rSearchItem.GetSelection();
566 	sal_Bool bBack = rSearchItem.GetBackward();
567 
568 	ScMarkData aNewMark( rMark );	// Tabellen-Markierungen kopieren
569 	aNewMark.ResetMark();
570 	for (SCCOL i=0; i<=MAXCOL; i++)
571 	{
572 		sal_Bool bFound = sal_True;
573 		SCsROW nRow = 0;
574 		SCsROW nEndRow;
575 		while (bFound && nRow <= MAXROW)
576 		{
577 			bFound = aCol[i].SearchStyleRange( nRow, nEndRow, pSearchStyle, bBack, bSelect, rMark );
578 			if (bFound)
579 			{
580 				if (nEndRow<nRow)
581 				{
582 					SCsROW nTemp = nRow;
583 					nRow = nEndRow;
584 					nEndRow = nTemp;
585 				}
586 				aNewMark.SetMultiMarkArea( ScRange( i,nRow,nTab, i,nEndRow,nTab ) );
587 				nRow = nEndRow + 1;
588 			}
589 		}
590 	}
591 
592 	rMark = aNewMark;		//	Markierung kopieren
593 							//!	pro Tabelle
594 
595 	return (aNewMark.IsMultiMarked());
596 }
597 
ReplaceAllStyle(const SvxSearchItem & rSearchItem,ScMarkData & rMark,ScDocument * pUndoDoc)598 sal_Bool ScTable::ReplaceAllStyle(const SvxSearchItem& rSearchItem, ScMarkData& rMark,
599 								ScDocument* pUndoDoc)
600 {
601 	sal_Bool bRet = SearchAllStyle(rSearchItem, rMark);
602 	if (bRet)
603 	{
604 		const ScStyleSheet* pReplaceStyle = (const ScStyleSheet*)
605 										pDocument->GetStyleSheetPool()->Find(
606 										rSearchItem.GetReplaceString(), SFX_STYLE_FAMILY_PARA );
607 
608 		if (pReplaceStyle)
609 		{
610 			if (pUndoDoc)
611 				pDocument->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab,
612 											IDF_ATTRIB, sal_True, pUndoDoc, &rMark );
613 			ApplySelectionStyle( *pReplaceStyle, rMark );
614 		}
615 		else
616 		{
617 			DBG_ERROR("pReplaceStyle==0");
618 		}
619 	}
620 
621 	return bRet;
622 }
623 
SearchAndReplace(const SvxSearchItem & rSearchItem,SCCOL & rCol,SCROW & rRow,ScMarkData & rMark,String & rUndoStr,ScDocument * pUndoDoc)624 sal_Bool ScTable::SearchAndReplace(const SvxSearchItem& rSearchItem,
625 								SCCOL& rCol, SCROW& rRow, ScMarkData& rMark,
626 								String& rUndoStr, ScDocument* pUndoDoc)
627 {
628 	sal_uInt16 nCommand = rSearchItem.GetCommand();
629 	sal_Bool bFound = sal_False;
630 	if ( ValidColRow(rCol, rRow) ||
631 		 ((nCommand == SVX_SEARCHCMD_FIND || nCommand == SVX_SEARCHCMD_REPLACE) &&
632 		   (((rCol == MAXCOLCOUNT || rCol == -1) && VALIDROW(rRow)) ||
633 			((rRow == MAXROWCOUNT || rRow == -1) && VALIDCOL(rCol))
634 		   )
635 		 )
636 	   )
637 	{
638 		sal_Bool bStyles = rSearchItem.GetPattern();
639 		if (bStyles)
640 		{
641 			if (nCommand == SVX_SEARCHCMD_FIND)
642 				bFound = SearchStyle(rSearchItem, rCol, rRow, rMark);
643 			else if (nCommand == SVX_SEARCHCMD_REPLACE)
644 				bFound = ReplaceStyle(rSearchItem, rCol, rRow, rMark, sal_False);
645 			else if (nCommand == SVX_SEARCHCMD_FIND_ALL)
646 				bFound = SearchAllStyle(rSearchItem, rMark);
647 			else if (nCommand == SVX_SEARCHCMD_REPLACE_ALL)
648 				bFound = ReplaceAllStyle(rSearchItem, rMark, pUndoDoc);
649 		}
650 		else
651 		{
652 			//	SearchParam no longer needed - SearchOptions contains all settings
653 			com::sun::star::util::SearchOptions aSearchOptions = rSearchItem.GetSearchOptions();
654 			aSearchOptions.Locale = *ScGlobal::GetLocale();
655 
656 			//	#107259# reflect UseAsianOptions flag in SearchOptions
657 			//	(use only ignore case and width if asian options are disabled).
658 			//	This is also done in SvxSearchDialog CommandHdl, but not in API object.
659 			if ( !rSearchItem.IsUseAsianOptions() )
660 				aSearchOptions.transliterateFlags &=
661 					( com::sun::star::i18n::TransliterationModules_IGNORE_CASE |
662 					  com::sun::star::i18n::TransliterationModules_IGNORE_WIDTH );
663 
664 			pSearchText = new utl::TextSearch( aSearchOptions );
665 
666 			if (nCommand == SVX_SEARCHCMD_FIND)
667 				bFound = Search(rSearchItem, rCol, rRow, rMark, rUndoStr, pUndoDoc);
668 			else if (nCommand == SVX_SEARCHCMD_FIND_ALL)
669 				bFound = SearchAll(rSearchItem, rMark, rUndoStr, pUndoDoc);
670 			else if (nCommand == SVX_SEARCHCMD_REPLACE)
671 				bFound = Replace(rSearchItem, rCol, rRow, rMark, rUndoStr, pUndoDoc);
672 			else if (nCommand == SVX_SEARCHCMD_REPLACE_ALL)
673 				bFound = ReplaceAll(rSearchItem, rMark, rUndoStr, pUndoDoc);
674 
675 			delete pSearchText;
676 			pSearchText = NULL;
677 		}
678 	}
679 	return bFound;
680 }
681 
682 
683 
684 
685 
686 
687