LibreOffice Module sc (master) 1
viewfun2.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source eCode Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <scitems.hxx>
21
22#include <sfx2/app.hxx>
24#include <editeng/boxitem.hxx>
25#include <editeng/fontitem.hxx>
26#include <editeng/lineitem.hxx>
28#include <svl/srchitem.hxx>
29#include <sfx2/linkmgr.hxx>
30#include <sfx2/dispatch.hxx>
31#include <sfx2/docfilt.hxx>
32#include <sfx2/docfile.hxx>
33#include <sfx2/objitem.hxx>
34#include <sfx2/viewfrm.hxx>
35#include <svl/numformat.hxx>
36#include <svl/stritem.hxx>
37#include <svl/zforlist.hxx>
38#include <svx/srchdlg.hxx>
39#include <svx/svdview.hxx>
40#include <vcl/svapp.hxx>
41#include <vcl/weld.hxx>
42#include <osl/diagnose.h>
43
44#include <viewfunc.hxx>
45#include <vcl/uitest/logger.hxx>
47
48#include <sc.hrc>
49#include <globstr.hrc>
50#include <scresid.hxx>
51
52#include <attrib.hxx>
53#include <autoform.hxx>
54#include <formulacell.hxx>
55#include <cellmergeoption.hxx>
56#include <compiler.hxx>
57#include <docfunc.hxx>
58#include <docpool.hxx>
59#include <docsh.hxx>
60#include <docoptio.hxx>
61#include <global.hxx>
62#include <patattr.hxx>
63#include <printfun.hxx>
64#include <refundo.hxx>
65#include <table.hxx>
66#include <tablink.hxx>
67#include <tabvwsh.hxx>
68#include <uiitems.hxx>
69#include <undoblk.hxx>
70#include <undotab.hxx>
71#include <sizedev.hxx>
72#include <editable.hxx>
73#include <docuno.hxx>
74#include <charthelper.hxx>
75#include <tabbgcolor.hxx>
76#include <clipparam.hxx>
77#include <prnsave.hxx>
78#include <searchresults.hxx>
79#include <tokenarray.hxx>
80#include <rowheightcontext.hxx>
81#include <LibreOfficeKit/LibreOfficeKitEnums.h>
82#include <comphelper/lok.hxx>
83#include <mergecellsdialog.hxx>
84#include <sheetevents.hxx>
85#include <columnspanset.hxx>
86
87#include <vector>
88#include <memory>
89#include <boost/property_tree/json_parser.hpp>
90#include <tools/json_writer.hxx>
91
92#include <officecfg/Office/Calc.hxx>
93
94using namespace com::sun::star;
95using ::editeng::SvxBorderLine;
96
97namespace {
98
99void collectUIInformation(std::map<OUString, OUString>&& aParameters, const OUString& rAction)
100{
101 EventDescription aDescription;
102 aDescription.aID = "grid_window";
103 aDescription.aAction = rAction;
104 aDescription.aParameters = std::move(aParameters);
105 aDescription.aParent = "MainWindow";
106 aDescription.aKeyWord = "ScGridWinUIObject";
107
108 UITestLogger::getInstance().logEvent(aDescription);
109}
110}
111
112using ::std::vector;
113using ::std::unique_ptr;
114
115bool ScViewFunc::AdjustBlockHeight( bool bPaint, ScMarkData* pMarkData )
116{
117 ScDocShell* pDocSh = GetViewData().GetDocShell();
118 if (!pMarkData)
119 pMarkData = &GetViewData().GetMarkData();
120
121 ScDocument& rDoc = pDocSh->GetDocument();
122 std::vector<sc::ColRowSpan> aMarkedRows = pMarkData->GetMarkedRowSpans();
123
124 if (aMarkedRows.empty())
125 {
126 SCROW nCurRow = GetViewData().GetCurY();
127 aMarkedRows.emplace_back(nCurRow, nCurRow);
128 }
129
131 {
132 SCCOLROW nStart = aMarkedRows[0].mnStart;
133 OnLOKSetWidthOrHeight(nStart, /*width: */ false);
134 }
135
136 double nPPTX = GetViewData().GetPPTX();
137 double nPPTY = GetViewData().GetPPTY();
138 Fraction aZoomX = GetViewData().GetZoomX();
139 Fraction aZoomY = GetViewData().GetZoomY();
140
141 ScSizeDeviceProvider aProv(pDocSh);
142 if (aProv.IsPrinter())
143 {
144 nPPTX = aProv.GetPPTX();
145 nPPTY = aProv.GetPPTY();
146 aZoomX = aZoomY = Fraction( 1, 1 );
147 }
148
149 sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice());
150 bool bAnyChanged = false;
151 for (const SCTAB& nTab : *pMarkData)
152 {
153 bool bChanged = false;
154 SCROW nPaintY = 0;
155 for (const auto& rRow : aMarkedRows)
156 {
157 SCROW nStartNo = rRow.mnStart;
158 SCROW nEndNo = rRow.mnEnd;
159 ScAddress aTopLeft(0, nStartNo, nTab);
160 rDoc.UpdateScriptTypes(aTopLeft, rDoc.GetSheetLimits().GetMaxColCount(), nEndNo-nStartNo+1);
161 if (rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, true))
162 {
163 if (!bChanged)
164 nPaintY = nStartNo;
165 bAnyChanged = bChanged = true;
166 }
167 }
168 // tdf#76183: recalculate objects' positions
169 if (bChanged)
170 rDoc.SetDrawPageSize(nTab);
171 if ( bPaint && bChanged )
172 pDocSh->PostPaint( 0, nPaintY, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab,
174 }
175
176 if ( bPaint && bAnyChanged )
177 pDocSh->UpdateOle(GetViewData());
178
180 {
181 SCTAB nTab = GetViewData().GetTabNo();
183 GetViewData().GetViewShell(),
184 false /* bColumns */, true /* bRows */,
185 true /* bSizes*/, false /* bHidden */, false /* bFiltered */,
186 false /* bGroups */, nTab);
188 }
189
190 return bAnyChanged;
191}
192
193bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, bool bApi )
194{
196 {
197 OnLOKSetWidthOrHeight(nStartRow, /*width: */ false);
198 }
199
200 ScDocShell* pDocSh = GetViewData().GetDocShell();
201 ScDocument& rDoc = pDocSh->GetDocument();
202 SCTAB nTab = GetViewData().GetTabNo();
203 double nPPTX = GetViewData().GetPPTX();
204 double nPPTY = GetViewData().GetPPTY();
205 Fraction aZoomX = GetViewData().GetZoomX();
206 Fraction aZoomY = GetViewData().GetZoomY();
207 sal_uInt16 nOldPixel = 0;
208 if (nStartRow == nEndRow)
209 nOldPixel = static_cast<sal_uInt16>(rDoc.GetRowHeight(nStartRow,nTab) * nPPTY);
210
211 ScSizeDeviceProvider aProv(pDocSh);
212 if (aProv.IsPrinter())
213 {
214 nPPTX = aProv.GetPPTX();
215 nPPTY = aProv.GetPPTY();
216 aZoomX = aZoomY = Fraction( 1, 1 );
217 }
218 sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice());
219 bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab, bApi);
220
221 // tdf#76183: recalculate objects' positions
222 if (bChanged)
223 rDoc.SetDrawPageSize(nTab);
224
225 if (bChanged && ( nStartRow == nEndRow ))
226 {
227 sal_uInt16 nNewPixel = static_cast<sal_uInt16>(rDoc.GetRowHeight(nStartRow,nTab) * nPPTY);
228 if ( nNewPixel == nOldPixel )
229 bChanged = false;
230 }
231
232 if ( bChanged )
233 pDocSh->PostPaint( 0, nStartRow, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab,
235
237 {
239 GetViewData().GetViewShell(),
240 false /* bColumns */, true /* bRows */,
241 true /* bSizes*/, false /* bHidden */, false /* bFiltered */,
242 false /* bGroups */, nTab);
244 }
245
246 return bChanged;
247}
248
249namespace {
250
251enum ScAutoSum
252{
253 ScAutoSumNone = 0,
254 ScAutoSumData,
255 ScAutoSumSum,
256 ScAutoSumAverage,
257 ScAutoSumMax,
258 ScAutoSumMin,
259 ScAutoSumCount,
260 ScAutoSumCountA,
261 ScAutoSumProduct,
262 ScAutoSumStDev,
263 ScAutoSumStDevP,
264 ScAutoSumVar,
265 ScAutoSumVarP,
266 ScAutoSumEnd
267};
268
269}
270
271static ScAutoSum lcl_IsAutoSumData( ScDocument& rDoc, SCCOL nCol, SCROW nRow,
272 SCTAB nTab, ScDirection eDir, SCCOLROW& nExtend )
273{
274 ScRefCellValue aCell(rDoc, ScAddress(nCol, nRow, nTab));
275 if (aCell.hasNumeric())
276 {
277 if (aCell.getType() == CELLTYPE_FORMULA)
278 {
279 ScAutoSum val = ScAutoSumNone;
280 ScTokenArray* pCode = aCell.getFormula()->GetCode();
281 if ( pCode )
282 {
283 switch( pCode->GetOuterFuncOpCode() )
284 {
285 case ocSum : val = ScAutoSumSum;
286 break;
287 case ocAverage : val = ScAutoSumAverage;
288 break;
289 case ocMax : val = ScAutoSumMax;
290 break;
291 case ocMin : val = ScAutoSumMin;
292 break;
293 case ocCount : val = ScAutoSumCount;
294 break;
295 case ocCount2 : val = ScAutoSumCountA;
296 break;
297 case ocProduct : val = ScAutoSumProduct;
298 break;
299 case ocStDev : val = ScAutoSumStDev;
300 break;
301 case ocStDevP : val = ScAutoSumStDevP;
302 break;
303 case ocVar : val = ScAutoSumVar;
304 break;
305 case ocVarP : val = ScAutoSumVarP;
306 break;
307 default :
308 break;
309 }
310 if ( pCode->GetAdjacentExtendOfOuterFuncRefs( nExtend,
311 ScAddress( nCol, nRow, nTab ), eDir ) )
312 return val;
313 }
314 }
315 return ScAutoSumData;
316 }
317 return ScAutoSumNone;
318}
319
320#define SC_AUTOSUM_MAXCOUNT 20
321
322static ScAutoSum lcl_SeekAutoSumData( ScDocument& rDoc, SCCOL& nCol, SCROW& nRow,
323 SCTAB nTab, ScDirection eDir, SCCOLROW& nExtend )
324{
325 sal_uInt16 nCount = 0;
327 {
328 if ( eDir == DIR_TOP )
329 {
330 if (nRow > 0)
331 --nRow;
332 else
333 return ScAutoSumNone;
334 }
335 else
336 {
337 if (nCol > 0)
338 --nCol;
339 else
340 return ScAutoSumNone;
341 }
342 ScAutoSum eSum;
343 if ( (eSum = lcl_IsAutoSumData(
344 rDoc, nCol, nRow, nTab, eDir, nExtend )) != ScAutoSumNone )
345 return eSum;
346 ++nCount;
347 }
348 return ScAutoSumNone;
349}
350
351#undef SC_AUTOSUM_MAXCOUNT
352
353static bool lcl_FindNextSumEntryInColumn( ScDocument& rDoc, SCCOL nCol, SCROW& nRow,
354 SCTAB nTab, SCCOLROW& nExtend, SCROW nMinRow )
355{
356 const SCROW nTmp = nRow;
357 ScAutoSum eSkip = ScAutoSumNone;
358 for (;;)
359 {
360 eSkip = lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_TOP, nExtend );
361 if (eSkip != ScAutoSumData || nRow <= nMinRow )
362 break;
363 --nRow;
364 }
365 return eSkip >= ScAutoSumSum && nRow < nTmp;
366}
367
368static bool lcl_FindNextSumEntryInRow( ScDocument& rDoc, SCCOL& nCol, SCROW nRow,
369 SCTAB nTab, SCCOLROW& nExtend, SCCOL nMinCol )
370{
371 const SCCOL nTmp = nCol;
372 ScAutoSum eSkip = ScAutoSumNone;
373 for (;;)
374 {
375 eSkip = lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_LEFT, nExtend );
376 if (eSkip != ScAutoSumData || nCol <= nMinCol )
377 break;
378 --nCol;
379 }
380 return eSkip >= ScAutoSumSum && nCol < nTmp;
381}
382
383static ScAutoSum lcl_GetAutoSumForColumnRange( ScDocument& rDoc, ScRangeList& rRangeList, const ScRange& rRange )
384{
385 const ScAddress aStart = rRange.aStart;
386 const ScAddress aEnd = rRange.aEnd;
387 if ( aStart.Col() != aEnd.Col() )
388 {
389 return ScAutoSumNone;
390 }
391
392 const SCTAB nTab = aEnd.Tab();
393 const SCCOL nCol = aEnd.Col();
394 SCROW nEndRow = aEnd.Row();
395 SCROW nStartRow = nEndRow;
396 SCCOLROW nExtend = 0;
397 ScAutoSum eSum = lcl_IsAutoSumData( rDoc, nCol, nEndRow, nTab, DIR_TOP, nExtend /*out*/ );
398
399 if ( eSum >= ScAutoSumSum )
400 {
401 bool bContinue = false;
402 do
403 {
404 rRangeList.push_back( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab ) );
405 nEndRow = static_cast< SCROW >( nExtend );
406 bContinue = lcl_FindNextSumEntryInColumn( rDoc, nCol, nEndRow /*inout*/, nTab, nExtend /*out*/, aStart.Row() );
407 if ( bContinue )
408 {
409 nStartRow = nEndRow;
410 }
411 } while ( bContinue );
412 }
413 else
414 {
415 while ( nStartRow > aStart.Row() )
416 {
417 eSum = lcl_IsAutoSumData( rDoc, nCol, nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ );
418 if (eSum >= ScAutoSumSum )
419 break;
420 --nStartRow;
421 }
422 rRangeList.push_back( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab ) );
423 if (eSum == ScAutoSumNone)
424 eSum = ScAutoSumData;
425 }
426
427 return eSum;
428}
429
430static ScAutoSum lcl_GetAutoSumForRowRange( ScDocument& rDoc, ScRangeList& rRangeList, const ScRange& rRange )
431{
432 const ScAddress aStart = rRange.aStart;
433 const ScAddress aEnd = rRange.aEnd;
434 if ( aStart.Row() != aEnd.Row() )
435 {
436 return ScAutoSumNone;
437 }
438
439 const SCTAB nTab = aEnd.Tab();
440 const SCROW nRow = aEnd.Row();
441 SCCOL nEndCol = aEnd.Col();
442 SCCOL nStartCol = nEndCol;
443 SCCOLROW nExtend = 0;
444 ScAutoSum eSum = lcl_IsAutoSumData( rDoc, nEndCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ );
445
446 if ( eSum >= ScAutoSumSum )
447 {
448 bool bContinue = false;
449 do
450 {
451 rRangeList.push_back( ScRange( nStartCol, nRow, nTab, nEndCol, nRow, nTab ) );
452 nEndCol = static_cast< SCCOL >( nExtend );
453 bContinue = lcl_FindNextSumEntryInRow( rDoc, nEndCol /*inout*/, nRow, nTab, nExtend /*out*/, aStart.Col() );
454 if ( bContinue )
455 {
456 nStartCol = nEndCol;
457 }
458 } while ( bContinue );
459 }
460 else
461 {
462 while ( nStartCol > aStart.Col() )
463 {
464 eSum = lcl_IsAutoSumData( rDoc, nStartCol-1, nRow, nTab, DIR_LEFT, nExtend /*out*/ );
465 if (eSum >= ScAutoSumSum )
466 break;
467 --nStartCol;
468 }
469 rRangeList.push_back( ScRange( nStartCol, nRow, nTab, nEndCol, nRow, nTab ) );
470 if (eSum == ScAutoSumNone)
471 eSum = ScAutoSumData;
472 }
473
474 return eSum;
475}
476
477static sal_Int8 GetSubTotal( const OpCode eCode )
478{
479 sal_Int8 val;
480 switch ( eCode )
481 {
482 case ocSum : val = 9;
483 break;
484 case ocAverage : val = 1;
485 break;
486 case ocMax : val = 4;
487 break;
488 case ocMin : val = 5;
489 break;
490 case ocCount : val = 2;
491 break;
492 case ocCount2 : val = 3;
493 break;
494 case ocProduct : val = 6;
495 break;
496 case ocStDev : val = 7;
497 break;
498 case ocStDevP : val = 8;
499 break;
500 case ocVar : val = 10;
501 break;
502 case ocVarP : val = 11;
503 break;
504 default : val = 9;
505 }
506
507 return val;
508}
509
511{
513 SCTAB nTab = GetViewData().GetTabNo();
514
515 SCCOL nCol = GetViewData().GetCurX();
516 SCROW nRow = GetViewData().GetCurY();
517
518 SCCOL nStartCol = nCol;
519 SCROW nStartRow = nRow;
520 SCCOL nEndCol = nCol;
521 SCROW nEndRow = nRow;
522 SCCOL nSeekCol = nCol;
523 SCROW nSeekRow = nRow;
524 SCCOLROW nExtend; // will become valid via reference for ScAutoSumSum
525
526 bool bCol = false;
527 bool bRow = false;
528
529 ScAutoSum eSum;
530 if ( nRow != 0
531 && ((eSum = lcl_IsAutoSumData( rDoc, nCol, nRow-1, nTab,
532 DIR_TOP, nExtend /*out*/ )) == ScAutoSumData )
533 && ((eSum = lcl_IsAutoSumData( rDoc, nCol, nRow-1, nTab,
534 DIR_LEFT, nExtend /*out*/ )) == ScAutoSumData )
535 )
536 {
537 bRow = true;
538 nSeekRow = nRow - 1;
539 }
540 else if ( nCol != 0 && (eSum = lcl_IsAutoSumData( rDoc, nCol-1, nRow, nTab,
541 DIR_LEFT, nExtend /*out*/ )) == ScAutoSumData )
542 {
543 bCol = true;
544 nSeekCol = nCol - 1;
545 }
546 else if ( (eSum = lcl_SeekAutoSumData( rDoc, nCol, nSeekRow, nTab, DIR_TOP, nExtend /*out*/ )) != ScAutoSumNone )
547 bRow = true;
548 else if (( eSum = lcl_SeekAutoSumData( rDoc, nSeekCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ )) != ScAutoSumNone )
549 bCol = true;
550
551 if ( bCol || bRow )
552 {
553 if ( bRow )
554 {
555 nStartRow = nSeekRow; // nSeekRow might be adjusted via reference
556 if ( eSum >= ScAutoSumSum && eSum < ScAutoSumEnd )
557 nEndRow = nStartRow; // only sum sums
558 else
559 nEndRow = nRow - 1; // maybe extend data area at bottom
560 }
561 else
562 {
563 nStartCol = nSeekCol; // nSeekCol might be adjusted via reference
564 if ( eSum >= ScAutoSumSum )
565 nEndCol = nStartCol; // only sum sums
566 else
567 nEndCol = nCol - 1; // maybe extend data area to the right
568 }
569 bool bContinue = false;
570 do
571 {
572 if ( eSum == ScAutoSumData )
573 {
574 if ( bRow )
575 {
576 while ( nStartRow != 0 && lcl_IsAutoSumData( rDoc, nCol,
577 nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ ) == eSum )
578 --nStartRow;
579 }
580 else
581 {
582 while ( nStartCol != 0 && lcl_IsAutoSumData( rDoc, nStartCol-1,
583 nRow, nTab, DIR_LEFT, nExtend /*out*/ ) == eSum )
584 --nStartCol;
585 }
586 }
587 rRangeList.push_back(
588 ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab ) );
589 if ( eSum >= ScAutoSumSum )
590 {
591 if ( bRow )
592 {
593 nEndRow = static_cast< SCROW >( nExtend );
594 bContinue = lcl_FindNextSumEntryInColumn( rDoc, nCol, nEndRow /*inout*/, nTab, nExtend /*out*/, 0 );
595 if ( bContinue )
596 {
597 nStartRow = nEndRow;
598 }
599 }
600 else
601 {
602 nEndCol = static_cast< SCCOL >( nExtend );
603 bContinue = lcl_FindNextSumEntryInRow( rDoc, nEndCol /*inout*/, nRow, nTab, nExtend /*out*/, 0 );
604 if ( bContinue )
605 {
606 nStartCol = nEndCol;
607 }
608 }
609 }
610 } while ( bContinue );
611 return true;
612 }
613 return false;
614}
615
616void ScViewFunc::EnterAutoSum(const ScRangeList& rRangeList, bool bSubTotal, const ScAddress& rAddr, const OpCode eCode)
617{
618 OUString aFormula = GetAutoSumFormula( rRangeList, bSubTotal, rAddr , eCode);
619 EnterBlock( aFormula, nullptr );
620}
621
622bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor, bool bContinue , const OpCode eCode)
623{
625 const SCTAB nTab = rRange.aStart.Tab();
626 SCCOL nStartCol = rRange.aStart.Col();
627 SCROW nStartRow = rRange.aStart.Row();
628 const SCCOL nEndCol = rRange.aEnd.Col();
629 const SCROW nEndRow = rRange.aEnd.Row();
630 SCCOLROW nExtend = 0; // out parameter for lcl_IsAutoSumData
631
632 // ignore rows at the top of the given range which don't contain autosum data
633 bool bRowData = false;
634 for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
635 {
636 for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
637 {
638 if ( lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_TOP, nExtend ) != ScAutoSumNone )
639 {
640 bRowData = true;
641 break;
642 }
643 }
644 if ( bRowData )
645 {
646 nStartRow = nRow;
647 break;
648 }
649 }
650 if ( !bRowData )
651 {
652 return false;
653 }
654
655 // ignore columns at the left of the given range which don't contain autosum data
656 bool bColData = false;
657 for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
658 {
659 for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
660 {
661 if ( lcl_IsAutoSumData( rDoc, nCol, nRow, nTab, DIR_LEFT, nExtend ) != ScAutoSumNone )
662 {
663 bColData = true;
664 break;
665 }
666 }
667 if ( bColData )
668 {
669 nStartCol = nCol;
670 break;
671 }
672 }
673 if ( !bColData )
674 {
675 return false;
676 }
677
678 const bool bEndRowEmpty = rDoc.IsBlockEmpty( nStartCol, nEndRow, nEndCol, nEndRow, nTab );
679 const bool bEndColEmpty = rDoc.IsBlockEmpty( nEndCol, nStartRow, nEndCol, nEndRow, nTab );
680 bool bRow = ( nStartRow != nEndRow ) && ( bEndRowEmpty || !bEndColEmpty );
681 bool bCol = ( nStartCol != nEndCol ) && ( bEndColEmpty || nStartRow == nEndRow );
682
683 // find an empty row for entering the result
684 SCROW nInsRow = nEndRow;
685 if ( bRow && !bEndRowEmpty )
686 {
687 if ( nInsRow < rDoc.MaxRow() )
688 {
689 ++nInsRow;
690 while ( !rDoc.IsBlockEmpty( nStartCol, nInsRow, nEndCol, nInsRow, nTab ) )
691 {
692 if ( nInsRow < rDoc.MaxRow() )
693 {
694 ++nInsRow;
695 }
696 else
697 {
698 bRow = false;
699 break;
700 }
701 }
702 }
703 else
704 {
705 bRow = false;
706 }
707 }
708
709 // find an empty column for entering the result
710 SCCOL nInsCol = nEndCol;
711 if ( bCol && !bEndColEmpty )
712 {
713 if ( nInsCol < rDoc.MaxCol() )
714 {
715 ++nInsCol;
716 while ( !rDoc.IsBlockEmpty( nInsCol, nStartRow, nInsCol, nEndRow, nTab ) )
717 {
718 if ( nInsCol < rDoc.MaxCol() )
719 {
720 ++nInsCol;
721 }
722 else
723 {
724 bCol = false;
725 break;
726 }
727 }
728 }
729 else
730 {
731 bCol = false;
732 }
733 }
734
735 if ( !bRow && !bCol )
736 {
737 return false;
738 }
739
740 SCCOL nMarkEndCol = nEndCol;
741 SCROW nMarkEndRow = nEndRow;
742 ScAutoSum eSum = ScAutoSumNone;
743 SCROW nColSums = 0;
744 SCCOL nRowSums = 0;
745 SCROW nColSumsStartRow = 0;
746 SCCOL nRowSumsStartCol = 0;
747
748 if ( bRow )
749 {
750 // calculate the row sums for all columns of the given range
751
752 SCROW nSumEndRow = nEndRow;
753
754 if ( bEndRowEmpty )
755 {
756 // the last row of the given range is empty;
757 // don't take into account for calculating the autosum
758 --nSumEndRow;
759 }
760 else
761 {
762 // increase mark range
763 ++nMarkEndRow;
764 }
765
766 for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
767 {
768 if ( !rDoc.IsBlockEmpty( nCol, nStartRow, nCol, nSumEndRow, nTab ) )
769 {
770 ScRangeList aRangeList;
771 // Include the originally selected start row.
772 const ScRange aRange( nCol, rRange.aStart.Row(), nTab, nCol, nSumEndRow, nTab );
773 if ( (eSum = lcl_GetAutoSumForColumnRange( rDoc, aRangeList, aRange )) != ScAutoSumNone )
774 {
775 if (++nRowSums == 1)
776 nRowSumsStartCol = aRangeList[0].aStart.Col();
777 const OUString aFormula = GetAutoSumFormula(
778 aRangeList, bSubTotal, ScAddress(nCol, nInsRow, nTab), eCode);
779 EnterData( nCol, nInsRow, nTab, aFormula );
780 }
781 }
782 }
783 }
784
785 if ( bCol )
786 {
787 // calculate the column sums for all rows of the given range
788
789 SCCOL nSumEndCol = nEndCol;
790
791 if ( bEndColEmpty )
792 {
793 // the last column of the given range is empty;
794 // don't take into account for calculating the autosum
795 --nSumEndCol;
796 }
797 else
798 {
799 // increase mark range
800 ++nMarkEndCol;
801 }
802
803 for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
804 {
805 if ( !rDoc.IsBlockEmpty( nStartCol, nRow, nSumEndCol, nRow, nTab ) )
806 {
807 ScRangeList aRangeList;
808 // Include the originally selected start column.
809 const ScRange aRange( rRange.aStart.Col(), nRow, nTab, nSumEndCol, nRow, nTab );
810 if ( (eSum = lcl_GetAutoSumForRowRange( rDoc, aRangeList, aRange )) != ScAutoSumNone )
811 {
812 if (++nColSums == 1)
813 nColSumsStartRow = aRangeList[0].aStart.Row();
814 const OUString aFormula = GetAutoSumFormula( aRangeList, bSubTotal, ScAddress(nInsCol, nRow, nTab), eCode );
815 EnterData( nInsCol, nRow, nTab, aFormula );
816 }
817 }
818 }
819 }
820
821 // Set new mark range and cursor position.
822 // For sum of sums (and data until sum) mark the actual resulting range if
823 // there is only one, or the data range if more than one. Otherwise use the
824 // original selection. All extended by end column/row where the sum is put.
825 const ScRange aMarkRange(
826 (eSum >= ScAutoSumSum ?
827 (nRowSums == 1 ? nRowSumsStartCol : nStartCol) :
828 rRange.aStart.Col()),
829 (eSum >= ScAutoSumSum ?
830 (nColSums == 1 ? nColSumsStartRow : nStartRow) :
831 rRange.aStart.Row()),
832 nTab, nMarkEndCol, nMarkEndRow, nTab );
833 MarkRange( aMarkRange, false, bContinue );
834 if ( bSetCursor )
835 {
836 SetCursor( nMarkEndCol, nMarkEndRow );
837 }
838
839 return true;
840}
841
842OUString ScViewFunc::GetAutoSumFormula( const ScRangeList& rRangeList, bool bSubTotal, const ScAddress& rAddr , const OpCode eCode)
843{
844 ScViewData& rViewData = GetViewData();
845 ScDocument& rDoc = rViewData.GetDocument();
846 ScTokenArray aArray(rDoc);
847
848 aArray.AddOpCode(bSubTotal ? ocSubTotal : eCode);
849 aArray.AddOpCode(ocOpen);
850
851 if (bSubTotal)
852 {
853 aArray.AddDouble( GetSubTotal( eCode ) );
854 aArray.AddOpCode(ocSep);
855 }
856
857 if(!rRangeList.empty())
858 {
859 ScRangeList aRangeList = rRangeList;
860 size_t ListSize = aRangeList.size();
861 for ( size_t i = 0; i < ListSize; ++i )
862 {
863 const ScRange & r = aRangeList[i];
864 if (i != 0)
865 aArray.AddOpCode(ocSep);
866 ScComplexRefData aRef;
867 aRef.InitRangeRel(rDoc, r, rAddr);
868 aArray.AddDoubleReference(aRef);
869 }
870 }
871
872 aArray.AddOpCode(ocClose);
873
874 ScCompiler aComp(rDoc, rAddr, aArray, rDoc.GetGrammar());
875 OUStringBuffer aBuf;
877 OUString aFormula = aBuf.makeStringAndClear();
878 aBuf.append('=');
879 aBuf.append(aFormula);
880 return aBuf.makeStringAndClear();
881}
882
883void ScViewFunc::EnterBlock( const OUString& rString, const EditTextObject* pData )
884{
885 // test for multi selection
886
887 SCCOL nCol = GetViewData().GetCurX();
888 SCROW nRow = GetViewData().GetCurY();
889 SCTAB nTab = GetViewData().GetTabNo();
891 if ( rMark.IsMultiMarked() )
892 {
893 rMark.MarkToSimple();
894 if ( rMark.IsMultiMarked() )
895 { // "Insert into multi selection not possible"
896 ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
897
898 // insert into single cell
899 if ( pData )
900 EnterData(nCol, nRow, nTab, *pData);
901 else
902 EnterData( nCol, nRow, nTab, rString );
903 return;
904 }
905 }
906
907 if (GetViewData().SelectionForbidsCellFill())
908 {
909 PaintArea(nCol, nRow, nCol, nRow); // possibly the edit-engine is still painted there
910 return;
911 }
912
914 OUString aNewStr = rString;
915 if ( pData )
916 {
917 const ScPatternAttr* pOldPattern = rDoc.GetPattern( nCol, nRow, nTab );
918 ScTabEditEngine aEngine( *pOldPattern, rDoc.GetEnginePool(), &rDoc );
920
921 ScEditAttrTester aTester( &aEngine );
922 if (!aTester.NeedsObject())
923 {
924 aNewStr = aEngine.GetText();
925 pData = nullptr;
926 }
927 }
928
929 // Insert via PasteFromClip
930 weld::WaitObject aWait(GetViewData().GetDialogParent());
931
932 ScAddress aPos( nCol, nRow, nTab );
933
935 pInsDoc->ResetClip( &rDoc, nTab );
936
937 if (aNewStr[0] == '=') // Formula ?
938 {
939 // SetString not possible, because in Clipboard-Documents nothing will be compiled!
940 pInsDoc->SetFormulaCell(aPos, new ScFormulaCell(rDoc, aPos, aNewStr));
941 }
942 else if ( pData )
943 {
944 // A copy of pData will be stored.
945 pInsDoc->SetEditText(aPos, *pData, rDoc.GetEditPool());
946 }
947 else
948 pInsDoc->SetString( nCol, nRow, nTab, aNewStr );
949
950 pInsDoc->SetClipArea( ScRange(aPos) );
951 // insert Block, with Undo etc.
952 if ( !PasteFromClip( InsertDeleteFlags::CONTENTS, pInsDoc.get(), ScPasteFunc::NONE, false, false,
954 return;
955
956 const SfxUInt32Item* pItem = pInsDoc->GetAttr(
957 nCol, nRow, nTab, ATTR_VALUE_FORMAT );
958 if ( pItem )
959 { // set number format if incompatible
960 // MarkData was already MarkToSimple'ed in PasteFromClip
961 const ScRange& aRange = rMark.GetMarkArea();
962 ScPatternAttr aPattern( rDoc.GetPool() );
963 aPattern.GetItemSet().Put( *pItem );
964 SvNumFormatType nNewType = rDoc.GetFormatTable()->GetType( pItem->GetValue() );
965 rDoc.ApplyPatternIfNumberformatIncompatible( aRange, rMark,
966 aPattern, nNewType );
967 }
968}
969
970// manual page break
971
972void ScViewFunc::InsertPageBreak( bool bColumn, bool bRecord, const ScAddress* pPos,
973 bool bSetModified )
974{
975 SCTAB nTab = GetViewData().GetTabNo();
976 ScAddress aCursor;
977 if (pPos)
978 aCursor = *pPos;
979 else
980 aCursor = ScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
981
982 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
983 InsertPageBreak( bColumn, aCursor, bRecord, bSetModified );
984
985 if ( bSuccess && bSetModified )
986 UpdatePageBreakData( true ); // for PageBreak-Mode
987}
988
989void ScViewFunc::DeletePageBreak( bool bColumn, bool bRecord, const ScAddress* pPos,
990 bool bSetModified )
991{
992 SCTAB nTab = GetViewData().GetTabNo();
993 ScAddress aCursor;
994 if (pPos)
995 aCursor = *pPos;
996 else
997 aCursor = ScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
998
999 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
1000 RemovePageBreak( bColumn, aCursor, bRecord, bSetModified );
1001
1002 if ( bSuccess && bSetModified )
1003 UpdatePageBreakData( true ); // for PageBreak-Mode
1004}
1005
1007{
1008 ScDocShell* pDocSh = GetViewData().GetDocShell();
1009 ScDocument& rDoc = pDocSh->GetDocument();
1010 SCTAB nTab = GetViewData().GetTabNo();
1011 bool bUndo(rDoc.IsUndoEnabled());
1012
1013 if (bUndo)
1014 {
1016 pUndoDoc->InitUndo( rDoc, nTab, nTab, true, true );
1017 rDoc.CopyToDocument( 0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc );
1018 pDocSh->GetUndoManager()->AddUndoAction(
1019 std::make_unique<ScUndoRemoveBreaks>( pDocSh, nTab, std::move(pUndoDoc) ) );
1020 }
1021
1022 rDoc.RemoveManualBreaks(nTab);
1023 rDoc.UpdatePageBreaks(nTab);
1024
1025 UpdatePageBreakData( true );
1026 pDocSh->SetDocumentModified();
1027 pDocSh->PostPaint( 0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, PaintPartFlags::Grid );
1028}
1029
1030void ScViewFunc::SetPrintZoom(sal_uInt16 nScale)
1031{
1032 ScDocShell* pDocSh = GetViewData().GetDocShell();
1033 SCTAB nTab = GetViewData().GetTabNo();
1034 pDocSh->SetPrintZoom( nTab, nScale, 0/*nPages*/ );
1035}
1036
1038{
1039 ScRange aRange;
1040 if ( GetViewData().GetSimpleArea( aRange ) != SC_MARK_SIMPLE )
1043}
1044
1045void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint,
1046 const OUString* pRepCol, const OUString* pRepRow,
1047 bool bAddPrint )
1048{
1049 // on all selected tables
1050
1051 ScDocShell* pDocSh = GetViewData().GetDocShell();
1052 ScDocument& rDoc = pDocSh->GetDocument();
1053 ScMarkData& rMark = GetViewData().GetMarkData();
1054 bool bUndo (rDoc.IsUndoEnabled());
1055
1056 std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
1057
1058 ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0);
1059
1060 for (const SCTAB& nTab : rMark)
1061 {
1062 ScRange aRange( 0,0,nTab );
1063
1064 // print ranges
1065
1066 if( !bAddPrint )
1067 rDoc.ClearPrintRanges( nTab );
1068
1069 if( bEntireSheet )
1070 {
1071 rDoc.SetPrintEntireSheet( nTab );
1072 }
1073 else if ( pPrint )
1074 {
1075 if ( !pPrint->isEmpty() )
1076 {
1078 sal_Int32 nPos = 0;
1079 do
1080 {
1081 const OUString aToken = pPrint->getToken(0, sep, nPos);
1082 if ( aRange.ParseAny( aToken, rDoc, aDetails ) & ScRefFlags::VALID )
1083 rDoc.AddPrintRange( nTab, aRange );
1084 }
1085 while (nPos >= 0);
1086 }
1087 }
1088 else // NULL = use selection (print range is always set), use empty string to delete all ranges
1089 {
1090 if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
1091 {
1092 rDoc.AddPrintRange( nTab, aRange );
1093 }
1094 else if ( rMark.IsMultiMarked() )
1095 {
1096 rMark.MarkToMulti();
1097 ScRangeListRef pList( new ScRangeList );
1098 rMark.FillRangeListWithMarks( pList.get(), false );
1099 for (size_t i = 0, n = pList->size(); i < n; ++i)
1100 {
1101 const ScRange & rR = (*pList)[i];
1102 rDoc.AddPrintRange(nTab, rR);
1103 }
1104 }
1105 }
1106
1107 // repeat columns
1108
1109 if ( pRepCol )
1110 {
1111 if ( pRepCol->isEmpty() )
1112 rDoc.SetRepeatColRange( nTab, std::nullopt );
1113 else
1114 if ( aRange.ParseAny( *pRepCol, rDoc, aDetails ) & ScRefFlags::VALID )
1115 rDoc.SetRepeatColRange( nTab, std::move(aRange) );
1116 }
1117
1118 // repeat rows
1119
1120 if ( pRepRow )
1121 {
1122 if ( pRepRow->isEmpty() )
1123 rDoc.SetRepeatRowRange( nTab, std::nullopt );
1124 else
1125 if ( aRange.ParseAny( *pRepRow, rDoc, aDetails ) & ScRefFlags::VALID )
1126 rDoc.SetRepeatRowRange( nTab, std::move(aRange) );
1127 }
1128 }
1129
1130 // undo (for all tables)
1131 if (bUndo)
1132 {
1133 SCTAB nCurTab = GetViewData().GetTabNo();
1134 std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver();
1136 {
1137 tools::JsonWriter aJsonWriter;
1138 pNewRanges->GetPrintRangesInfo(aJsonWriter);
1139
1140 SfxViewShell* pViewShell = GetViewData().GetViewShell();
1141 const std::string message = aJsonWriter.extractAsStdString();
1142 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_PRINT_RANGES, message.c_str());
1143 }
1144
1145 pDocSh->GetUndoManager()->AddUndoAction(
1146 std::make_unique<ScUndoPrintRange>( pDocSh, nCurTab, std::move(pOldRanges), std::move(pNewRanges) ) );
1147 }
1148 else
1149 pOldRanges.reset();
1150
1151 // update page breaks
1152
1153 for (const auto& rTab : rMark)
1154 ScPrintFunc( pDocSh, pDocSh->GetPrinter(), rTab ).UpdatePages();
1155
1156 SfxBindings& rBindings = GetViewData().GetBindings();
1157 rBindings.Invalidate( SID_DELETE_PRINTAREA );
1158
1159 pDocSh->SetDocumentModified();
1160}
1161
1162// Merge cells
1163
1164bool ScViewFunc::TestMergeCells() // pre-test (for menu)
1165{
1166 // simple test: true if there's a selection but no multi selection and not filtered
1167
1168 const ScMarkData& rMark = GetViewData().GetMarkData();
1169 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
1170 {
1171 ScRange aRange;
1172 bool bMergeable = ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE );
1173 bMergeable = bMergeable && ( aRange.aStart.Col() != aRange.aEnd.Col() ||
1174 aRange.aStart.Row() != aRange.aEnd.Row() );
1175 return bMergeable;
1176 }
1177 else
1178 return false;
1179}
1180
1181bool ScViewFunc::MergeCells( bool bApi, bool& rDoContents, bool bCenter )
1182{
1183 // Editable- and Being-Nested- test must be at the beginning (in DocFunc too),
1184 // so that the Contents-QueryBox won't appear
1185 ScEditableTester aTester( this );
1186 if (!aTester.IsEditable())
1187 {
1188 ErrorMessage(aTester.GetMessageId());
1189 return false;
1190 }
1191
1192 ScMarkData& rMark = GetViewData().GetMarkData();
1193 rMark.MarkToSimple();
1194 if (!rMark.IsMarked())
1195 {
1196 ErrorMessage(STR_NOMULTISELECT);
1197 return false;
1198 }
1199
1200 ScDocShell* pDocSh = GetViewData().GetDocShell();
1201 ScDocument& rDoc = pDocSh->GetDocument();
1202
1203 const ScRange& aMarkRange = rMark.GetMarkArea();
1204 SCCOL nStartCol = aMarkRange.aStart.Col();
1205 SCROW nStartRow = aMarkRange.aStart.Row();
1206 SCTAB nStartTab = aMarkRange.aStart.Tab();
1207 SCCOL nEndCol = aMarkRange.aEnd.Col();
1208 SCROW nEndRow = aMarkRange.aEnd.Row();
1209 SCTAB nEndTab = aMarkRange.aEnd.Tab();
1210 if ( nStartCol == nEndCol && nStartRow == nEndRow )
1211 {
1212 // nothing to do
1213 return true;
1214 }
1215
1216 if ( rDoc.HasAttrib( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
1218 { // "Don't nest merging !"
1219 ErrorMessage(STR_MSSG_MERGECELLS_0);
1220 return false;
1221 }
1222
1223 // Check for the contents of all selected tables.
1224 bool bAskDialog = false;
1225 ScCellMergeOption aMergeOption(nStartCol, nStartRow, nEndCol, nEndRow, bCenter);
1226 for (const SCTAB& i : rMark)
1227 {
1228 aMergeOption.maTabs.insert(i);
1229
1230 sc::MultiDataCellState aState = rDoc.HasMultipleDataCells(aMergeOption.getSingleRange(i));
1231 switch (aState.meState)
1232 {
1234 {
1235 // this range contains multiple data cells.
1236 bAskDialog = true;
1237 break;
1238 }
1240 {
1241 // this range contains only one data cell.
1242 if (nStartCol != aState.mnCol1 || nStartRow != aState.mnRow1)
1243 rDoContents = true; // move the value to the top-left.
1244 break;
1245 }
1246 default:
1247 ;
1248 }
1249 }
1250
1251 bool bOk = true;
1252 bool bEmptyMergedCells = officecfg::Office::Calc::Compatibility::MergeCells::EmptyMergedCells::get();
1253
1254 if (bAskDialog)
1255 {
1256 bool bShowDialog = officecfg::Office::Calc::Compatibility::MergeCells::ShowDialog::get();
1257 if (!bApi && bShowDialog)
1258 {
1259 ScMergeCellsDialog aBox(GetViewData().GetDialogParent());
1260 sal_uInt16 nRetVal = aBox.run();
1261
1262 if ( nRetVal == RET_OK )
1263 {
1264 switch (aBox.GetMergeCellsOption())
1265 {
1267 rDoContents = true;
1268 break;
1270 bEmptyMergedCells = false;
1271 break;
1273 bEmptyMergedCells = true;
1274 break;
1275 default:
1276 assert(!"Unknown option for merge cells.");
1277 break;
1278 }
1279 }
1280 else if ( nRetVal == RET_CANCEL )
1281 bOk = false;
1282 }
1283 }
1284
1285 if (bOk)
1286 {
1287 bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, true/*bRecord*/, bApi, bEmptyMergedCells );
1288
1289 if (bOk)
1290 {
1291 SetCursor( nStartCol, nStartRow );
1292 //DoneBlockMode( sal_False);
1293 Unmark();
1294
1295 pDocSh->UpdateOle(GetViewData());
1297
1298 OUString aStartAddress = aMarkRange.aStart.GetColRowString();
1299 OUString aEndAddress = aMarkRange.aEnd.GetColRowString();
1300
1301 collectUIInformation({{"RANGE", aStartAddress + ":" + aEndAddress}}, "MERGE_CELLS");
1302 }
1303 }
1304
1305 return bOk;
1306}
1307
1309{
1310 bool bMerged = false;
1311 ScRange aRange;
1312 if (GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1313 {
1315 if ( rDoc.HasAttrib( aRange, HasAttrFlags::Merged ) )
1316 bMerged = true;
1317 }
1318 return bMerged;
1319}
1320
1321static bool lcl_extendMergeRange(ScCellMergeOption& rOption, const ScRange& rRange)
1322{
1323 bool bExtended = false;
1324 if (rOption.mnStartCol > rRange.aStart.Col())
1325 {
1326 rOption.mnStartCol = rRange.aStart.Col();
1327 bExtended = true;
1328 }
1329 if (rOption.mnStartRow > rRange.aStart.Row())
1330 {
1331 rOption.mnStartRow = rRange.aStart.Row();
1332 bExtended = true;
1333 }
1334 if (rOption.mnEndCol < rRange.aEnd.Col())
1335 {
1336 rOption.mnEndCol = rRange.aEnd.Col();
1337 bExtended = true;
1338 }
1339 if (rOption.mnEndRow < rRange.aEnd.Row())
1340 {
1341 rOption.mnEndRow = rRange.aEnd.Row();
1342 bExtended = true;
1343 }
1344 return bExtended;
1345}
1346
1348{
1349 ScRange aRange;
1350 ScEditableTester aTester( this );
1351 if (!aTester.IsEditable())
1352 {
1353 ErrorMessage(aTester.GetMessageId());
1354 return false;
1355 }
1356 else if (GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1357 {
1359 ScRange aExtended( aRange );
1360 rDoc.ExtendMerge( aExtended );
1361 ScDocShell* pDocSh = GetViewData().GetDocShell();
1362 const ScMarkData& rMark = GetViewData().GetMarkData();
1363 ScCellMergeOption aOption(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row());
1364 bool bExtended = false;
1365 do
1366 {
1367 bExtended = false;
1368 for (const SCTAB& i : rMark)
1369 {
1370 aOption.maTabs.insert(i);
1371 aExtended.aStart.SetTab(i);
1372 aExtended.aEnd.SetTab(i);
1373 rDoc.ExtendMerge(aExtended);
1374 rDoc.ExtendOverlapped(aExtended);
1375
1376 // Expand the current range to be inclusive of all merged
1377 // areas on all sheets.
1378 bExtended = lcl_extendMergeRange(aOption, aExtended);
1379 }
1380 }
1381 while (bExtended);
1382
1383 bool bOk = pDocSh->GetDocFunc().UnmergeCells(aOption, true/*bRecord*/, nullptr);
1384 aExtended = aOption.getFirstSingleRange();
1385 MarkRange( aExtended );
1386
1387 if (bOk)
1388 pDocSh->UpdateOle(GetViewData());
1389 }
1390
1391 OUString aCellLocation = aRange.aStart.GetColRowString();
1392 collectUIInformation({{"CELL", aCellLocation}}, "UNMERGE_CELL");
1393
1394 return true;
1395}
1396
1398{
1399 ScRange aRange;
1400 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1401 {
1402 ScDocShell* pDocSh = GetViewData().GetDocShell();
1403 const ScMarkData& rMark = GetViewData().GetMarkData();
1404 bool bSuccess = pDocSh->GetDocFunc().FillSimple( aRange, &rMark, eDir, false );
1405 if (bSuccess)
1406 {
1407 pDocSh->UpdateOle(GetViewData());
1409
1410 auto& rDoc = pDocSh->GetDocument();
1411 bool bDoAutoSpell = rDoc.GetDocOptions().IsAutoSpell();
1412 if ( bDoAutoSpell )
1413 {
1414 // Copy AutoSpellData from above(left/right/below) if no selection.
1415 switch (eDir)
1416 {
1417 case FILL_TO_BOTTOM:
1418 if (aRange.aStart.Row() > 0 && aRange.aStart.Row() == aRange.aEnd.Row())
1419 aRange.aStart.IncRow(-1);
1420 break;
1421 case FILL_TO_TOP:
1422 if (aRange.aEnd.Row() < rDoc.MaxRow() && aRange.aStart.Row() == aRange.aEnd.Row())
1423 aRange.aEnd.IncRow(1);
1424 break;
1425 case FILL_TO_RIGHT:
1426 if (aRange.aStart.Col() > 0 && aRange.aStart.Col() == aRange.aEnd.Col())
1427 aRange.aStart.IncCol(-1);
1428 break;
1429 case FILL_TO_LEFT:
1430 if (aRange.aEnd.Col() < rDoc.MaxCol() && aRange.aStart.Col() == aRange.aEnd.Col())
1431 aRange.aEnd.IncCol(1);
1432 break;
1433 }
1434 CopyAutoSpellData(eDir, aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(),
1435 ::std::numeric_limits<sal_uLong>::max());
1436 }
1437
1438 // Invalidate cell slots and update input line with new content.
1440 }
1441 }
1442 else
1443 ErrorMessage(STR_NOMULTISELECT);
1444}
1445
1447 double fStart, double fStep, double fMax )
1448{
1449 ScRange aRange;
1450 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1451 {
1452 ScDocShell* pDocSh = GetViewData().GetDocShell();
1453 const ScMarkData& rMark = GetViewData().GetMarkData();
1454 bool bSuccess = pDocSh->GetDocFunc().
1455 FillSeries( aRange, &rMark, eDir, eCmd, eDateCmd,
1456 fStart, fStep, fMax, false );
1457 if (bSuccess)
1458 {
1459 pDocSh->UpdateOle(GetViewData());
1461
1463 }
1464 }
1465 else
1466 ErrorMessage(STR_NOMULTISELECT);
1467}
1468
1469void ScViewFunc::FillAuto( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
1470 SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount )
1471{
1472 SCTAB nTab = GetViewData().GetTabNo();
1473 ScRange aRange( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab );
1474 ScRange aSourceRange( aRange );
1475 ScDocShell* pDocSh = GetViewData().GetDocShell();
1476 const ScMarkData& rMark = GetViewData().GetMarkData();
1477 bool bSuccess = pDocSh->GetDocFunc().
1478 FillAuto( aRange, &rMark, eDir, nCount, false );
1479 if (!bSuccess)
1480 return;
1481
1482 MarkRange( aRange, false ); // aRange was modified in FillAuto
1483 pDocSh->UpdateOle(GetViewData());
1485
1486 bool bDoAutoSpell = pDocSh->GetDocument().GetDocOptions().IsAutoSpell();
1487 if ( bDoAutoSpell )
1488 CopyAutoSpellData(eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount);
1489
1491 if (!pModelObj)
1492 return;
1493
1494 ScRangeList aChangeRanges;
1495 ScRange aChangeRange( aRange );
1496 switch (eDir)
1497 {
1498 case FILL_TO_BOTTOM:
1499 aChangeRange.aStart.SetRow( aSourceRange.aEnd.Row() + 1 );
1500 break;
1501 case FILL_TO_TOP:
1502 aChangeRange.aEnd.SetRow( aSourceRange.aStart.Row() - 1 );
1503 break;
1504 case FILL_TO_RIGHT:
1505 aChangeRange.aStart.SetCol( aSourceRange.aEnd.Col() + 1 );
1506 break;
1507 case FILL_TO_LEFT:
1508 aChangeRange.aEnd.SetCol( aSourceRange.aStart.Col() - 1 );
1509 break;
1510 default:
1511 break;
1512 }
1513 aChangeRanges.push_back( aChangeRange );
1514 HelperNotifyChanges::Notify(*pModelObj, aChangeRanges);
1515}
1516
1517void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
1518 SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount )
1519{
1520 const ScDocument* pDoc = &GetViewData().GetDocument();
1521 SCTAB nTab = GetViewData().GetTabNo();
1522 CellType eCellType;
1523
1524 ScGridWindow* pWin = GetActiveWin();
1525 if ( pWin->InsideVisibleRange(nStartCol, nStartRow) && pWin->InsideVisibleRange(nEndCol, nEndRow) )
1526 {
1527 if ( nCount == ::std::numeric_limits<sal_uLong>::max() )
1528 {
1529 switch( eDir )
1530 {
1531 case FILL_TO_BOTTOM:
1532 for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1533 {
1534 eCellType = pDoc->GetCellType(nColItr, nStartRow, nTab); // We need this optimization only for EditTextObject source cells
1535 if (eCellType != CELLTYPE_EDIT)
1536 continue;
1537
1538 const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nColItr, nStartRow);
1539 if ( !pRanges )
1540 continue;
1541 for ( SCROW nRowItr = nStartRow + 1; nRowItr <= nEndRow; ++nRowItr )
1542 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1543 }
1544 break;
1545 case FILL_TO_TOP:
1546 for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1547 {
1548 eCellType = pDoc->GetCellType(nColItr, nEndRow, nTab); // We need this optimization only for EditTextObject source cells
1549 if (eCellType != CELLTYPE_EDIT)
1550 continue;
1551
1552 const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nColItr, nEndRow);
1553 if ( !pRanges )
1554 continue;
1555 for ( SCROW nRowItr = nEndRow - 1; nRowItr >= nStartRow; --nRowItr )
1556 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1557 }
1558 break;
1559 case FILL_TO_RIGHT:
1560 for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1561 {
1562 eCellType = pDoc->GetCellType(nStartCol, nRowItr, nTab); // We need this optimization only for EditTextObject source cells
1563 if (eCellType != CELLTYPE_EDIT)
1564 continue;
1565
1566 const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nStartCol, nRowItr);
1567 if ( !pRanges )
1568 continue;
1569 for ( SCCOL nColItr = nStartCol + 1; nColItr <= nEndCol; ++nColItr )
1570 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1571 }
1572 break;
1573 case FILL_TO_LEFT:
1574 for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1575 {
1576 eCellType = pDoc->GetCellType(nEndCol, nRowItr, nTab); // We need this optimization only for EditTextObject source cells
1577 if (eCellType != CELLTYPE_EDIT)
1578 continue;
1579
1580 const std::vector<editeng::MisspellRanges>* pRanges = pWin->GetAutoSpellData(nEndCol, nRowItr);
1581 if ( !pRanges )
1582 continue;
1583 for ( SCCOL nColItr = nEndCol - 1; nColItr >= nStartCol; --nColItr )
1584 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1585 }
1586 break;
1587 }
1588 return;
1589 }
1590
1591 typedef const std::vector<editeng::MisspellRanges>* MisspellRangesType;
1592 SCROW nRowRepeatSize = nEndRow - nStartRow + 1;
1593 SCCOL nColRepeatSize = nEndCol - nStartCol + 1;
1594 SCROW nTillRow = 0;
1595 SCCOL nTillCol = 0;
1596 std::vector<std::vector<MisspellRangesType>> aSourceSpellRanges(nRowRepeatSize, std::vector<MisspellRangesType>(nColRepeatSize, nullptr));
1597
1598 for ( SCROW nRowIdx = 0; nRowIdx < nRowRepeatSize; ++nRowIdx )
1599 {
1600 for ( SCCOL nColIdx = 0; nColIdx < nColRepeatSize; ++nColIdx )
1601 {
1602 eCellType = pDoc->GetCellType(nStartCol + nColIdx, nStartRow + nRowIdx, nTab); // We need this optimization only for EditTextObject source cells
1603 if (eCellType != CELLTYPE_EDIT)
1604 continue;
1605
1606 aSourceSpellRanges[nRowIdx][nColIdx] = pWin->GetAutoSpellData( nStartCol + nColIdx, nStartRow + nRowIdx );
1607 }
1608 }
1609
1610 switch( eDir )
1611 {
1612 case FILL_TO_BOTTOM:
1613 nTillRow = nEndRow + nCount;
1614 for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1615 {
1616 for ( SCROW nRowItr = nEndRow + 1; nRowItr <= nTillRow; ++nRowItr )
1617 {
1618 size_t nSourceRowIdx = ( nRowItr - nEndRow - 1 ) % nRowRepeatSize;
1619 MisspellRangesType pRanges = aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
1620 if ( !pRanges )
1621 continue;
1622 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1623 }
1624 }
1625 break;
1626
1627 case FILL_TO_TOP:
1628 nTillRow = nStartRow - nCount;
1629 for ( SCCOL nColItr = nStartCol; nColItr <= nEndCol; ++nColItr )
1630 {
1631 for ( SCROW nRowItr = nStartRow - 1; nRowItr >= nTillRow; --nRowItr )
1632 {
1633 size_t nSourceRowIdx = nRowRepeatSize - 1 - ( ( nStartRow - 1 - nRowItr ) % nRowRepeatSize );
1634 MisspellRangesType pRanges = aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
1635 if ( !pRanges )
1636 continue;
1637 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1638 }
1639 }
1640 break;
1641
1642 case FILL_TO_RIGHT:
1643 nTillCol = nEndCol + nCount;
1644 for ( SCCOL nColItr = nEndCol + 1; nColItr <= nTillCol; ++nColItr )
1645 {
1646 size_t nSourceColIdx = ( nColItr - nEndCol - 1 ) % nColRepeatSize;
1647 for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1648 {
1649 MisspellRangesType pRanges = aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
1650 if ( !pRanges )
1651 continue;
1652 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1653 }
1654 }
1655 break;
1656
1657 case FILL_TO_LEFT:
1658 nTillCol = nStartCol - nCount;
1659 for ( SCCOL nColItr = nStartCol - 1; nColItr >= nTillCol; --nColItr )
1660 {
1661 size_t nSourceColIdx = nColRepeatSize - 1 - ( ( nStartCol - 1 - nColItr ) % nColRepeatSize );
1662 for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; ++nRowItr )
1663 {
1664 MisspellRangesType pRanges = aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
1665 if ( !pRanges )
1666 continue;
1667 pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
1668 }
1669 }
1670 break;
1671 }
1672 }
1673 else
1675
1676}
1677
1678void ScViewFunc::FillTab( InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink )
1679{
1681 ScEditableTester aTester( this );
1682 if (!aTester.IsEditable())
1683 {
1684 ErrorMessage(aTester.GetMessageId());
1685 return;
1686 }
1687
1688 ScDocShell* pDocSh = GetViewData().GetDocShell();
1689 ScDocument& rDoc = pDocSh->GetDocument();
1690 ScMarkData& rMark = GetViewData().GetMarkData();
1691 SCTAB nTab = GetViewData().GetTabNo();
1692 bool bUndo(rDoc.IsUndoEnabled());
1693
1694 ScRange aMarkRange;
1695 rMark.MarkToSimple();
1696 bool bMulti = rMark.IsMultiMarked();
1697 if (bMulti)
1698 aMarkRange = rMark.GetMultiMarkArea();
1699 else if (rMark.IsMarked())
1700 aMarkRange = rMark.GetMarkArea();
1701 else
1702 aMarkRange = ScRange( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
1703
1704 ScDocumentUniquePtr pUndoDoc;
1705
1706 if (bUndo)
1707 {
1708 pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
1709 pUndoDoc->InitUndo( rDoc, nTab, nTab );
1710
1711 for (const SCTAB& i : rMark)
1712 if (i != nTab )
1713 {
1714 pUndoDoc->AddUndoTab( i, i );
1715 aMarkRange.aStart.SetTab( i );
1716 aMarkRange.aEnd.SetTab( i );
1717 rDoc.CopyToDocument( aMarkRange, InsertDeleteFlags::ALL, bMulti, *pUndoDoc );
1718 }
1719 }
1720
1721 if (bMulti)
1722 rDoc.FillTabMarked( nTab, rMark, nFlags, nFunction, bSkipEmpty, bAsLink );
1723 else
1724 {
1725 aMarkRange.aStart.SetTab( nTab );
1726 aMarkRange.aEnd.SetTab( nTab );
1727 rDoc.FillTab( aMarkRange, rMark, nFlags, nFunction, bSkipEmpty, bAsLink );
1728 }
1729
1730 if (bUndo)
1731 {
1732 pDocSh->GetUndoManager()->AddUndoAction(
1733 std::make_unique<ScUndoFillTable>( pDocSh, rMark,
1734 aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), nTab,
1735 aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab,
1736 std::move(pUndoDoc), bMulti, nTab, nFlags, nFunction, bSkipEmpty, bAsLink ) );
1737 }
1738
1739 pDocSh->PostPaintGridAll();
1740 pDocSh->PostDataChanged();
1741}
1742
1759{
1760 ScRange aRange;
1761 GetViewData().GetSimpleArea( aRange );
1762 aRange.PutInOrder();
1763
1764 SCTAB nTab = GetViewData().GetCurPos().Tab();
1765 SCCOL nStartX = aRange.aStart.Col();
1766 SCROW nStartY = aRange.aStart.Row();
1767 SCCOL nEndX = aRange.aEnd.Col();
1768 SCROW nEndY = aRange.aEnd.Row();
1769
1771
1772 if (nEndY >= rDoc.MaxRow())
1773 // Nothing to fill.
1774 return;
1775
1776 // Make sure the selection is not empty
1777 if ( rDoc.IsBlockEmpty( nStartX, nStartY, nEndX, nEndY, nTab ) )
1778 return;
1779
1780 // If there is data in all columns immediately below the selection then
1781 // switch to overwriting fill.
1782 SCROW nOverWriteEndRow = rDoc.MaxRow();
1783 for (SCCOL nCol = nStartX; nCol <= nEndX; ++nCol)
1784 {
1785 if (rDoc.HasData( nCol, nEndY + 1, nTab))
1786 {
1787 // Determine the shortest data column to end the fill.
1788 SCROW nY = nEndY + 1;
1789 // FindAreaPos() returns the start row of the next data block if
1790 // the current row is the last row of a data block and an empty
1791 // cell follows. Somewhat unexpected behaviour...
1792 // So check beforehand if there is one non-empty cell following.
1793 if (rDoc.HasData( nCol, nY + 1, nTab))
1794 {
1795 rDoc.FindAreaPos( nCol, nY, nTab, SC_MOVE_DOWN);
1796 if (nOverWriteEndRow > nY)
1797 nOverWriteEndRow = nY;
1798 }
1799 else
1800 {
1801 nOverWriteEndRow = nY;
1802 }
1803 }
1804 else
1805 {
1806 nOverWriteEndRow = 0;
1807 break; // for
1808 }
1809 }
1810
1811 if (nOverWriteEndRow > nEndY)
1812 {
1813 FillAuto( FILL_TO_BOTTOM, nStartX, nStartY, nEndX, nEndY, nOverWriteEndRow - nEndY);
1814 return;
1815 }
1816
1817 // Non-overwriting fill follows.
1818
1819 const bool bDataLeft = (nStartX > 0);
1820 if (!bDataLeft && nEndX >= rDoc.MaxCol())
1821 // Absolutely no data left or right of selection.
1822 return;
1823
1824 // Check that there is
1825 // 1) data immediately left (preferred) or right of start (row) of selection
1826 // 2) data there below
1827 // 3) no data immediately below selection
1828
1829 SCCOL nMovX = (bDataLeft ? nStartX - 1 : nEndX + 1);
1830 SCROW nMovY = nStartY;
1831 bool bDataFound = (rDoc.HasData( nMovX, nStartY, nTab) && rDoc.HasData( nMovX, nStartY + 1, nTab));
1832 if (!bDataFound && bDataLeft && nEndX < rDoc.MaxCol())
1833 {
1834 nMovX = nEndX + 1; // check right
1835 bDataFound = (rDoc.HasData( nMovX, nStartY, nTab) && rDoc.HasData( nMovX, nStartY + 1, nTab));
1836 }
1837
1838 if (!(bDataFound && rDoc.IsEmptyData( nStartX, nEndY + 1, nEndX, nEndY + 1, nTab )))
1839 return;
1840
1841 // Get end of data left or right.
1842 rDoc.FindAreaPos( nMovX, nMovY, nTab, SC_MOVE_DOWN);
1843 // Find minimum end row of below empty area and data right.
1844 for (SCCOL nX = nStartX; nX <= nEndX; ++nX)
1845 {
1846 SCROW nY = nEndY + 1;
1847 // Get next row with data in this column.
1848 rDoc.FindAreaPos( nX, nY, nTab, SC_MOVE_DOWN);
1849 if (nMovY == rDoc.MaxRow() && nY == rDoc.MaxRow())
1850 {
1851 // FindAreaPos() returns MAXROW also if there is no data at all
1852 // from the start, so check if that contains data if the nearby
1853 // (left or right) data ends there and increment if no data
1854 // here, pretending the next data would be thereafter so nMovY
1855 // will not be decremented.
1856 if (!rDoc.HasData( nX, nY, nTab))
1857 ++nY;
1858 }
1859 if (nMovY > nY - 1)
1860 nMovY = nY - 1;
1861 }
1862
1863 if (nMovY > nEndY)
1864 {
1865 FillAuto( FILL_TO_BOTTOM, nStartX, nStartY, nEndX, nEndY, nMovY - nEndY);
1866 }
1867}
1868
1870{
1871 ScRange aRange;
1872 GetViewData().GetSimpleArea(aRange);
1873 aRange.PutInOrder();
1874
1875 ScDocShell* pDocSh = GetViewData().GetDocShell();
1876 pDocSh->GetDocFunc().ConvertFormulaToValue(aRange, true);
1877 pDocSh->PostPaint(aRange, PaintPartFlags::Grid);
1878}
1879
1881{
1882 ScMarkData aFuncMark = GetViewData().GetMarkData();
1883 if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
1884 {
1885 // no selection -> use cursor position
1886
1887 ScAddress aCursor( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
1888 aFuncMark.SetMarkArea( ScRange( aCursor ) );
1889 }
1890
1891 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
1892 TransliterateText( aFuncMark, nType, false );
1893 if (bSuccess)
1894 {
1896 }
1897}
1898
1899// AutoFormat
1900
1902{
1903 ScAutoFormatData* pData = nullptr;
1904 SCCOL nStartCol;
1905 SCROW nStartRow;
1906 SCTAB nStartTab;
1907 SCCOL nEndCol;
1908 SCROW nEndRow;
1909 SCTAB nEndTab;
1910 if (GetViewData().GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
1911 {
1912 if ( nEndCol-nStartCol >= 3 && nEndRow-nStartRow >= 3 )
1913 {
1915 pData = new ScAutoFormatData;
1916 rDoc.GetAutoFormatData( nStartTab, nStartCol,nStartRow,nEndCol,nEndRow, *pData );
1917 }
1918 }
1919 return pData;
1920}
1921
1922void ScViewFunc::AutoFormat( sal_uInt16 nFormatNo )
1923{
1924 ScRange aRange;
1925 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1926 {
1927 ScDocShell* pDocSh = GetViewData().GetDocShell();
1928 ScMarkData& rMark = GetViewData().GetMarkData();
1929
1930 bool bSuccess = pDocSh->GetDocFunc().AutoFormat( aRange, &rMark, nFormatNo, false );
1931 if (bSuccess)
1932 pDocSh->UpdateOle(GetViewData());
1933 }
1934 else
1935 ErrorMessage(STR_NOMULTISELECT);
1936}
1937
1938// Search & Replace
1939
1941 bool bAddUndo, bool bIsApi )
1942{
1943 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty);
1944 ScDocShell* pDocSh = GetViewData().GetDocShell();
1945 ScDocument& rDoc = pDocSh->GetDocument();
1946 ScMarkData& rMark = GetViewData().GetMarkData();
1947 if (bAddUndo && !rDoc.IsUndoEnabled())
1948 bAddUndo = false;
1949
1950 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() && (pSearchItem->HasStartPoint()) )
1951 {
1952 // No selection -> but we have a start point (top left corner of the
1953 // current view), start searching from there, not from the current
1954 // cursor position.
1955 SCCOL nPosX;
1956 SCROW nPosY;
1957
1958 int nPixelX = pSearchItem->GetStartPointX() * GetViewData().GetPPTX();
1959 int nPixelY = pSearchItem->GetStartPointY() * GetViewData().GetPPTY();
1960
1961 GetViewData().GetPosFromPixel(nPixelX, nPixelY, GetViewData().GetActivePart(), nPosX, nPosY);
1962
1963 AlignToCursor( nPosX, nPosY, SC_FOLLOW_JUMP );
1964 SetCursor( nPosX, nPosY, true );
1965 }
1966
1967 SCCOL nCol, nOldCol;
1968 SCROW nRow, nOldRow;
1969 SCTAB nTab, nOldTab;
1970 nCol = nOldCol = GetViewData().GetCurX();
1971 nRow = nOldRow = GetViewData().GetCurY();
1972 nTab = nOldTab = GetViewData().GetTabNo();
1973
1974 SvxSearchCmd nCommand = pSearchItem->GetCommand();
1975 bool bAllTables = pSearchItem->IsAllTables();
1976 std::set<SCTAB> aOldSelectedTables;
1977 SCTAB nLastTab = rDoc.GetTableCount() - 1;
1978 SCTAB nStartTab, nEndTab;
1979 if ( bAllTables )
1980 {
1981 nStartTab = 0;
1982 nEndTab = nLastTab;
1983 std::set<SCTAB> aTmp(rMark.begin(), rMark.end());
1984 aOldSelectedTables.swap(aTmp);
1985 }
1986 else
1987 {
1988 nStartTab = rMark.GetFirstSelected();
1989 nEndTab = rMark.GetLastSelected();
1990 }
1991
1992 if ( nCommand == SvxSearchCmd::FIND
1993 || nCommand == SvxSearchCmd::FIND_ALL)
1994 bAddUndo = false;
1995
1997
1998 ScDocumentUniquePtr pUndoDoc;
1999 std::unique_ptr<ScMarkData> pUndoMark;
2000 OUString aUndoStr;
2001 if (bAddUndo)
2002 {
2003 pUndoMark.reset(new ScMarkData(rMark)); // Mark is being modified
2004 if ( nCommand == SvxSearchCmd::REPLACE_ALL )
2005 {
2006 pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
2007 pUndoDoc->InitUndo( rDoc, nStartTab, nEndTab );
2008 }
2009 }
2010
2011 if ( bAllTables )
2012 {
2013 for ( SCTAB j = nStartTab; j <= nEndTab; j++ )
2014 {
2015 rMark.SelectTable( j, true );
2016 }
2017 }
2018
2019 DoneBlockMode(true); // don't delete mark
2020 InitOwnBlockMode( ScRange( nCol, nRow, nStartTab, nCol, nRow, nEndTab));
2021
2022 // If search starts at the beginning don't ask again whether it shall start at the beginning
2023 bool bFirst = true;
2024 if ( nCol == 0 && nRow == 0 && nTab == nStartTab && !pSearchItem->GetBackward() )
2025 bFirst = false;
2026
2027 bool bFound = false;
2028 while (true)
2029 {
2031 ScRangeList aMatchedRanges;
2032 if (rDoc.SearchAndReplace(*pSearchItem, nCol, nRow, nTab, rMark, aMatchedRanges, aUndoStr, pUndoDoc.get()))
2033 {
2034 bFound = true;
2035 if (bAddUndo)
2036 {
2038 std::make_unique<ScUndoReplace>( GetViewData().GetDocShell(), *pUndoMark,
2039 nCol, nRow, nTab,
2040 aUndoStr, std::move(pUndoDoc), pSearchItem ) );
2041 }
2042
2043 if (nCommand == SvxSearchCmd::FIND_ALL || nCommand == SvxSearchCmd::REPLACE_ALL)
2044 {
2045 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
2047
2048 if (bShow && pViewFrm && !comphelper::LibreOfficeKit::isActive())
2049 {
2050 pViewFrm->ShowChildWindow(sc::SearchResultsDlgWrapper::GetChildWindowId());
2051 SfxChildWindow* pWnd = pViewFrm->GetChildWindow(sc::SearchResultsDlgWrapper::GetChildWindowId());
2052 if (pWnd)
2053 {
2054 sc::SearchResultsDlg* pDlg = static_cast<sc::SearchResultsDlg*>(pWnd->GetController().get());
2055 if (pDlg)
2056 {
2057 const bool bCellNotes = (pSearchItem->GetCellType() == SvxSearchCellType::NOTE);
2058 // ScCellIterator iterates over cells with content,
2059 // for empty cells iterate over match positions.
2060 const bool bEmptyCells = (!bCellNotes
2061 && ((nCommand == SvxSearchCmd::FIND_ALL
2062 && ScDocument::IsEmptyCellSearch(*pSearchItem))
2063 || (nCommand == SvxSearchCmd::REPLACE_ALL
2064 && pSearchItem->GetReplaceString().isEmpty())));
2065 pDlg->FillResults(rDoc, aMatchedRanges, bCellNotes, bEmptyCells);
2066 }
2067 }
2068 }
2069
2070 rMark.ResetMark();
2071 for (size_t i = 0, n = aMatchedRanges.size(); i < n; ++i)
2072 {
2073 const ScRange& r = aMatchedRanges[i];
2074 if (r.aStart.Tab() == nTab)
2075 rMark.SetMultiMarkArea(r);
2076 }
2077 }
2078
2079 break; // break 'while (TRUE)'
2080 }
2081 else if ( bFirst && (nCommand == SvxSearchCmd::FIND ||
2082 nCommand == SvxSearchCmd::REPLACE) )
2083 {
2084 bFirst = false;
2086 if (!bIsApi)
2087 {
2088 if ( nStartTab == nEndTab )
2089 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::EndSheet);
2090 else
2092
2093 rDoc.GetSearchAndReplaceStart( *pSearchItem, nCol, nRow );
2094 if (pSearchItem->GetBackward())
2095 nTab = nEndTab;
2096 else
2097 nTab = nStartTab;
2098 }
2099 else
2100 {
2101 break; // break 'while (TRUE)'
2102 }
2103 }
2104 else // nothing found
2105 {
2106 if ( nCommand == SvxSearchCmd::FIND_ALL || nCommand == SvxSearchCmd::REPLACE_ALL )
2107 {
2108 pDocSh->PostPaintGridAll(); // Mark
2109 }
2110
2112 if (!bIsApi)
2113 {
2114 GetViewData().GetViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, pSearchItem->GetSearchString().toUtf8().getStr());
2115 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NotFound);
2116 }
2117
2118 break; // break 'while (TRUE)'
2119 }
2120 } // of while true
2121
2122 if (!aOldSelectedTables.empty())
2123 {
2124 // restore originally selected table
2125 for (SCTAB i = 0; i <= nEndTab; ++i)
2126 rMark.SelectTable(i, false);
2127
2128 for (const auto& rTab : aOldSelectedTables)
2129 rMark.SelectTable(rTab, true);
2130
2131 if ( bFound )
2132 { // if a table is selected as a "match" it remains selected.
2133 rMark.SelectTable( nTab, true );
2134 // It's a swap if only one table was selected before
2136 if ( aOldSelectedTables.size() == 1 && nTab != nOldTab )
2137 rMark.SelectTable( nOldTab, false );
2138 }
2139 }
2140
2141 // Avoid LOK selection notifications before we have all the results.
2145
2146 if ( bFound )
2147 {
2148 if ( nTab != GetViewData().GetTabNo() )
2149 SetTabNo( nTab );
2150
2151 // if nothing is marked, DoneBlockMode, then marking can start
2152 // directly from this place via Shift-Cursor
2153 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2154 DoneBlockMode(true);
2155
2156 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
2157 SetCursor( nCol, nRow, true );
2158
2160 {
2161 Point aCurPos = GetViewData().GetScrPos(nCol, nRow, GetViewData().GetActivePart());
2162
2163 // just update the cell selection
2164 ScGridWindow* pGridWindow = GetViewData().GetActiveWin();
2165 // Don't move cell selection handles for find-all: selection of all but the first result would be lost.
2166 if (pGridWindow && nCommand == SvxSearchCmd::FIND)
2167 {
2168 // move the cell selection handles
2169 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_RESET, aCurPos.X(), aCurPos.Y());
2170 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_START, aCurPos.X(), aCurPos.Y());
2171 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_END, aCurPos.X(), aCurPos.Y());
2172 }
2173
2174 if (pGridWindow)
2175 {
2176 std::vector<tools::Rectangle> aLogicRects;
2177 pGridWindow->GetCellSelection(aLogicRects);
2178
2179 boost::property_tree::ptree aTree;
2180 aTree.put("searchString", pSearchItem->GetSearchString().toUtf8().getStr());
2181 aTree.put("highlightAll", nCommand == SvxSearchCmd::FIND_ALL);
2182
2183 boost::property_tree::ptree aSelections;
2184 for (const tools::Rectangle& rLogicRect : aLogicRects)
2185 {
2186 boost::property_tree::ptree aSelection;
2187 aSelection.put("part", OString::number(nTab).getStr());
2188 aSelection.put("rectangles", rLogicRect.toString().getStr());
2189 aSelections.push_back(std::make_pair("", aSelection));
2190 }
2191 aTree.add_child("searchResultSelection", aSelections);
2192
2193 std::stringstream aStream;
2194 boost::property_tree::write_json(aStream, aTree);
2195 OString aPayload = aStream.str().c_str();
2196 SfxViewShell* pViewShell = GetViewData().GetViewShell();
2197 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
2198
2199 // Trigger LOK_CALLBACK_TEXT_SELECTION now.
2201 }
2202 }
2203
2204 if ( nCommand == SvxSearchCmd::REPLACE
2205 || nCommand == SvxSearchCmd::REPLACE_ALL )
2206 {
2207 if ( nCommand == SvxSearchCmd::REPLACE )
2208 {
2209 pDocSh->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PaintPartFlags::Grid );
2210
2211 // jump to next cell if we replaced everything in the cell
2212 // where the cursor was positioned (but avoid switching tabs)
2213 if ( nCol == nOldCol && nRow == nOldRow && nTab == nOldTab )
2214 {
2215 SvxSearchItem aSearchItem = ScGlobal::GetSearchItem();
2216 aSearchItem.SetCommand(SvxSearchCmd::FIND);
2217 aSearchItem.SetWhich(SID_SEARCH_ITEM);
2218
2219 ScRangeList aMatchedRanges;
2220 ScTable::UpdateSearchItemAddressForReplace( aSearchItem, nCol, nRow );
2221 if ( rDoc.SearchAndReplace( aSearchItem, nCol, nRow, nTab, rMark, aMatchedRanges, aUndoStr ) &&
2222 ( nTab == nOldTab ) &&
2223 ( nCol != nOldCol || nRow != nOldRow ) )
2224 {
2225 AlignToCursor(nCol, nRow, SC_FOLLOW_JUMP);
2226 SetCursor( nCol, nRow, true );
2227 }
2228 }
2229 }
2230 else
2231 pDocSh->PostPaintGridAll();
2232 pDocSh->SetDocumentModified();
2233 }
2234 else if ( nCommand == SvxSearchCmd::FIND_ALL )
2235 pDocSh->PostPaintGridAll(); // mark
2237 }
2238 return bFound;
2239}
2240
2241// Goal Seek
2242
2243void ScViewFunc::Solve( const ScSolveParam& rParam )
2244{
2246
2247 SCCOL nDestCol = rParam.aRefVariableCell.Col();
2248 SCROW nDestRow = rParam.aRefVariableCell.Row();
2249 SCTAB nDestTab = rParam.aRefVariableCell.Tab();
2250
2251 ScEditableTester aTester( rDoc, nDestTab, nDestCol,nDestRow, nDestCol,nDestRow );
2252 if (!aTester.IsEditable())
2253 {
2254 ErrorMessage(aTester.GetMessageId());
2255 return;
2256 }
2257
2258 OUString aTargetValStr;
2259 if ( rParam.pStrTargetVal )
2260 aTargetValStr = *rParam.pStrTargetVal;
2261
2262 OUString aMsgStr;
2263 OUString aResStr;
2264 double nSolveResult;
2265
2267
2268 bool bExact =
2269 rDoc.Solver(
2270 rParam.aRefFormulaCell.Col(),
2271 rParam.aRefFormulaCell.Row(),
2272 rParam.aRefFormulaCell.Tab(),
2273 nDestCol, nDestRow, nDestTab,
2274 aTargetValStr,
2275 nSolveResult );
2276
2278
2279 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
2280 sal_uLong nFormat = 0;
2281 const ScPatternAttr* pPattern = rDoc.GetPattern( nDestCol, nDestRow, nDestTab );
2282 if ( pPattern )
2283 nFormat = pPattern->GetNumberFormat( pFormatter );
2284 const Color* p;
2285 pFormatter->GetOutputString( nSolveResult, nFormat, aResStr, &p );
2286
2287 if ( bExact )
2288 {
2289 aMsgStr += ScResId( STR_MSSG_SOLVE_0 ) +
2290 aResStr +
2291 ScResId( STR_MSSG_SOLVE_1 );
2292 }
2293 else
2294 {
2295 aMsgStr = ScResId( STR_MSSG_SOLVE_2 ) +
2296 ScResId( STR_MSSG_SOLVE_3 ) +
2297 aResStr +
2298 ScResId( STR_MSSG_SOLVE_4 );
2299 }
2300
2301 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetViewData().GetDialogParent(),
2302 VclMessageType::Question, VclButtonsType::YesNo, aMsgStr));
2303 xBox->set_title(ScResId(STR_MSSG_DOSUBTOTALS_0));
2304 xBox->set_default_response(RET_NO);
2305 if (xBox->run() == RET_YES)
2306 EnterValue( nDestCol, nDestRow, nDestTab, nSolveResult );
2307
2309}
2310
2311// multi operation
2312
2313void ScViewFunc::TabOp( const ScTabOpParam& rParam, bool bRecord )
2314{
2315 ScRange aRange;
2316 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
2317 {
2318 ScDocShell* pDocSh = GetViewData().GetDocShell();
2319 ScMarkData& rMark = GetViewData().GetMarkData();
2320 pDocSh->GetDocFunc().TabOp( aRange, &rMark, rParam, bRecord, false );
2321 }
2322 else
2323 ErrorMessage(STR_NOMULTISELECT);
2324}
2325
2326void ScViewFunc::MakeScenario( const OUString& rName, const OUString& rComment,
2327 const Color& rColor, ScScenarioFlags nFlags )
2328{
2329 ScDocShell* pDocSh = GetViewData().GetDocShell();
2330 ScMarkData& rMark = GetViewData().GetMarkData();
2331 SCTAB nTab = GetViewData().GetTabNo();
2332
2333 SCTAB nNewTab = pDocSh->MakeScenario( nTab, rName, rComment, rColor, nFlags, rMark );
2334 if (nFlags & ScScenarioFlags::CopyAll)
2335 SetTabNo( nNewTab, true ); // ScScenarioFlags::CopyAll -> visible
2336 else
2337 {
2338 SfxBindings& rBindings = GetViewData().GetBindings();
2339 rBindings.Invalidate( SID_STATUS_DOCPOS ); // Statusbar
2340 rBindings.Invalidate( SID_ROWCOL_SELCOUNT ); // Statusbar
2341 rBindings.Invalidate( SID_TABLES_COUNT );
2342 rBindings.Invalidate( SID_SELECT_SCENARIO );
2343 rBindings.Invalidate( FID_TABLE_SHOW );
2344 }
2345}
2346
2348{
2349 ScEditableTester aTester( this );
2350 if (!aTester.IsEditable())
2351 {
2352 ErrorMessage(aTester.GetMessageId());
2353 return;
2354 }
2355
2356 // Undo: apply attributes
2357
2359 ScPatternAttr aPattern( rDoc.GetPool() );
2361 aPattern.GetItemSet().Put( ScProtectionAttr( true ) );
2362 ApplySelectionPattern(aPattern);
2363}
2364
2365void ScViewFunc::UseScenario( const OUString& rName )
2366{
2367 ScDocShell* pDocSh = GetViewData().GetDocShell();
2368 SCTAB nTab = GetViewData().GetTabNo();
2369
2370 DoneBlockMode();
2371 InitOwnBlockMode( ScRange( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab));
2372 pDocSh->UseScenario( nTab, rName );
2373}
2374
2375// Insert table
2376
2377bool ScViewFunc::InsertTable( const OUString& rName, SCTAB nTab, bool bRecord )
2378{
2379 // Order Table/Name is inverted for DocFunc
2380 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
2381 InsertTable( nTab, rName, bRecord, false );
2382 if (bSuccess)
2383 SetTabNo( nTab, true );
2384
2385 return bSuccess;
2386}
2387
2388// Insert tables
2389
2390void ScViewFunc::InsertTables(std::vector<OUString>& aNames, SCTAB nTab,
2391 SCTAB nCount, bool bRecord )
2392{
2393 ScDocShell* pDocSh = GetViewData().GetDocShell();
2394 ScDocument& rDoc = pDocSh->GetDocument();
2395 if (bRecord && !rDoc.IsUndoEnabled())
2396 bRecord = false;
2397
2398 weld::WaitObject aWait(GetViewData().GetDialogParent());
2399
2400 if (bRecord)
2401 {
2402 rDoc.BeginDrawUndo(); // InsertTab creates a SdrUndoNewPage
2403 }
2404
2405 bool bFlag=false;
2406
2407 if(aNames.empty())
2408 {
2409 rDoc.CreateValidTabNames(aNames, nCount);
2410 }
2411 if (rDoc.InsertTabs(nTab, aNames))
2412 {
2413 pDocSh->Broadcast( ScTablesHint( SC_TABS_INSERTED, nTab, nCount ) );
2414 bFlag = true;
2415 }
2416
2417 if (!bFlag)
2418 return;
2419
2420 if (bRecord)
2421 pDocSh->GetUndoManager()->AddUndoAction(
2422 std::make_unique<ScUndoInsertTables>( pDocSh, nTab, std::move(aNames)));
2423
2424 // Update views
2425
2426 SetTabNo( nTab, true );
2427 pDocSh->PostPaintExtras();
2428 pDocSh->SetDocumentModified();
2429 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2430}
2431
2432bool ScViewFunc::AppendTable( const OUString& rName, bool bRecord )
2433{
2434 ScDocShell* pDocSh = GetViewData().GetDocShell();
2435 ScDocument& rDoc = pDocSh->GetDocument();
2436 if (bRecord && !rDoc.IsUndoEnabled())
2437 bRecord = false;
2438
2439 weld::WaitObject aWait(GetViewData().GetDialogParent());
2440
2441 if (bRecord)
2442 rDoc.BeginDrawUndo(); // InsertTab creates a SdrUndoNewPage
2443
2444 if (rDoc.InsertTab( SC_TAB_APPEND, rName ))
2445 {
2446 SCTAB nTab = rDoc.GetTableCount()-1;
2447 if (bRecord)
2448 pDocSh->GetUndoManager()->AddUndoAction(
2449 std::make_unique<ScUndoInsertTab>( pDocSh, nTab, true, rName));
2450 GetViewData().InsertTab( nTab );
2451 SetTabNo( nTab, true );
2452 pDocSh->PostPaintExtras();
2453 pDocSh->SetDocumentModified();
2454 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2455 return true;
2456 }
2457 else
2458 {
2459 return false;
2460 }
2461}
2462
2463void ScViewFunc::DeleteTable( SCTAB nTab, bool bRecord )
2464{
2465 ScDocShell* pDocSh = GetViewData().GetDocShell();
2466 ScDocument& rDoc = pDocSh->GetDocument();
2467
2468 bool bSuccess = pDocSh->GetDocFunc().DeleteTable( nTab, bRecord );
2469 if (bSuccess)
2470 {
2471 SCTAB nNewTab = nTab;
2472 if ( nNewTab >= rDoc.GetTableCount() )
2473 --nNewTab;
2474 SetTabNo( nNewTab, true );
2475 }
2476}
2477
2478//only use this method for undo for now, all sheets must be connected
2479//this method doesn't support undo for now, merge it when it with the other method later
2480void ScViewFunc::DeleteTables( const SCTAB nTab, SCTAB nSheets )
2481{
2482 ScDocShell* pDocSh = GetViewData().GetDocShell();
2483 ScDocument& rDoc = pDocSh->GetDocument();
2484 bool bVbaEnabled = rDoc.IsInVBAMode();
2485 SCTAB nNewTab = nTab;
2486 weld::WaitObject aWait(GetViewData().GetDialogParent());
2487
2488 while ( nNewTab > 0 && !rDoc.IsVisible( nNewTab ) )
2489 --nNewTab;
2490
2491 if (!rDoc.DeleteTabs(nTab, nSheets))
2492 return;
2493
2494 if( bVbaEnabled )
2495 {
2496 for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
2497 {
2498 OUString sCodeName;
2499 bool bHasCodeName = rDoc.GetCodeName( nTab + aTab, sCodeName );
2500 if ( bHasCodeName )
2501 VBA_DeleteModule( *pDocSh, sCodeName );
2502 }
2503 }
2504
2505 pDocSh->Broadcast( ScTablesHint( SC_TABS_DELETED, nTab, nSheets ) );
2506 if ( nNewTab >= rDoc.GetTableCount() )
2507 nNewTab = rDoc.GetTableCount() - 1;
2508 SetTabNo( nNewTab, true );
2509
2510 pDocSh->PostPaintExtras();
2511 pDocSh->SetDocumentModified();
2512
2513 SfxApplication* pSfxApp = SfxGetpApp(); // Navigator
2514 pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2515 pSfxApp->Broadcast( SfxHint( SfxHintId::ScDbAreasChanged ) );
2516 pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) );
2517}
2518
2519bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, bool bRecord )
2520{
2521 ScDocShell* pDocSh = GetViewData().GetDocShell();
2522 ScDocument& rDoc = pDocSh->GetDocument();
2523 bool bVbaEnabled = rDoc.IsInVBAMode();
2524 SCTAB nNewTab = TheTabs.front();
2525 weld::WaitObject aWait(GetViewData().GetDialogParent());
2526 if (bRecord && !rDoc.IsUndoEnabled())
2527 bRecord = false;
2528 if ( bVbaEnabled )
2529 bRecord = false;
2530
2531 while ( nNewTab > 0 && !rDoc.IsVisible( nNewTab ) )
2532 --nNewTab;
2533
2534 bool bWasLinked = false;
2535 ScDocumentUniquePtr pUndoDoc;
2536 std::unique_ptr<ScRefUndoData> pUndoData;
2537 if (bRecord)
2538 {
2539 pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
2540 SCTAB nCount = rDoc.GetTableCount();
2541
2542 OUString aOldName;
2543 for(size_t i=0; i<TheTabs.size(); ++i)
2544 {
2545 SCTAB nTab = TheTabs[i];
2546 if (i==0)
2547 pUndoDoc->InitUndo( rDoc, nTab,nTab, true,true ); // incl. column/fow flags
2548 else
2549 pUndoDoc->AddUndoTab( nTab,nTab, true,true ); // incl. column/fow flags
2550
2551 rDoc.CopyToDocument(0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, InsertDeleteFlags::ALL,false, *pUndoDoc );
2552 rDoc.GetName( nTab, aOldName );
2553 pUndoDoc->RenameTab( nTab, aOldName );
2554 if (rDoc.IsLinked(nTab))
2555 {
2556 bWasLinked = true;
2557 pUndoDoc->SetLink( nTab, rDoc.GetLinkMode(nTab), rDoc.GetLinkDoc(nTab),
2558 rDoc.GetLinkFlt(nTab), rDoc.GetLinkOpt(nTab),
2559 rDoc.GetLinkTab(nTab),
2560 rDoc.GetLinkRefreshDelay(nTab) );
2561 }
2562 if ( rDoc.IsScenario(nTab) )
2563 {
2564 pUndoDoc->SetScenario( nTab, true );
2565 OUString aComment;
2566 Color aColor;
2567 ScScenarioFlags nScenFlags;
2568 rDoc.GetScenarioData( nTab, aComment, aColor, nScenFlags );
2569 pUndoDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
2570 bool bActive = rDoc.IsActiveScenario( nTab );
2571 pUndoDoc->SetActiveScenario( nTab, bActive );
2572 }
2573 pUndoDoc->SetVisible( nTab, rDoc.IsVisible( nTab ) );
2574 pUndoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) );
2575 auto pSheetEvents = rDoc.GetSheetEvents( nTab );
2576 pUndoDoc->SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) );
2577 pUndoDoc->SetLayoutRTL( nTab, rDoc.IsLayoutRTL( nTab ) );
2578
2579 if ( rDoc.IsTabProtected( nTab ) )
2580 pUndoDoc->SetTabProtection(nTab, rDoc.GetTabProtection(nTab));
2581
2582 // Drawing-Layer is responsible for its Undo !!!
2583 // pUndoDoc->TransferDrawPage(rDoc, nTab,nTab);
2584 }
2585
2586 pUndoDoc->AddUndoTab( 0, nCount-1 ); // all Tabs for references
2587
2588 rDoc.BeginDrawUndo(); // DeleteTab creates a SdrUndoDelPage
2589
2590 pUndoData.reset(new ScRefUndoData( &rDoc ));
2591 }
2592
2593 bool bDelDone = false;
2594
2595 for(int i=TheTabs.size()-1; i>=0; --i)
2596 {
2597 OUString sCodeName;
2598 bool bHasCodeName = rDoc.GetCodeName( TheTabs[i], sCodeName );
2599 if (rDoc.DeleteTab(TheTabs[i]))
2600 {
2601 bDelDone = true;
2602 if( bVbaEnabled && bHasCodeName )
2603 {
2604 VBA_DeleteModule( *pDocSh, sCodeName );
2605 }
2606 pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[i] ) );
2607 }
2608 }
2609 if (bRecord)
2610 {
2611 pDocSh->GetUndoManager()->AddUndoAction(
2612 std::make_unique<ScUndoDeleteTab>( GetViewData().GetDocShell(), TheTabs,
2613 std::move(pUndoDoc), std::move(pUndoData) ));
2614 }
2615
2616 if (bDelDone)
2617 {
2618 if ( nNewTab >= rDoc.GetTableCount() )
2619 nNewTab = rDoc.GetTableCount() - 1;
2620
2621 SetTabNo( nNewTab, true );
2622
2623 if (bWasLinked)
2624 {
2625 pDocSh->UpdateLinks(); // update Link-Manager
2626 GetViewData().GetBindings().Invalidate(SID_LINKS);
2627 }
2628
2629 pDocSh->PostPaintExtras();
2630 pDocSh->SetDocumentModified();
2631
2632 SfxApplication* pSfxApp = SfxGetpApp(); // Navigator
2633 pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2634 pSfxApp->Broadcast( SfxHint( SfxHintId::ScDbAreasChanged ) );
2635 pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) );
2636 }
2637 return bDelDone;
2638}
2639
2640bool ScViewFunc::RenameTable( const OUString& rName, SCTAB nTab )
2641{
2642 // order Table/Name is inverted for DocFunc
2643 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
2644 RenameTable( nTab, rName, true, false );
2645 if (bSuccess)
2646 {
2647 // the table name might be part of a formula
2649 }
2650 return bSuccess;
2651}
2652
2653bool ScViewFunc::SetTabBgColor( const Color& rColor, SCTAB nTab )
2654{
2655 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().SetTabBgColor( nTab, rColor, true, false );
2656 if (bSuccess)
2657 {
2659 }
2660 return bSuccess;
2661}
2662
2663bool ScViewFunc::SetTabBgColor( ScUndoTabColorInfo::List& rUndoSetTabBgColorInfoList )
2664{
2665 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().SetTabBgColor( rUndoSetTabBgColorInfoList, false );
2666 if (bSuccess)
2667 {
2669 }
2670 return bSuccess;
2671}
2672
2673void ScViewFunc::InsertAreaLink( const OUString& rFile,
2674 const OUString& rFilter, const OUString& rOptions,
2675 const OUString& rSource )
2676{
2677 ScDocShell* pDocSh = GetViewData().GetDocShell();
2678 SCCOL nPosX = GetViewData().GetCurX();
2679 SCROW nPosY = GetViewData().GetCurY();
2680 SCTAB nTab = GetViewData().GetTabNo();
2681 ScAddress aPos( nPosX, nPosY, nTab );
2682
2683 pDocSh->GetDocFunc().InsertAreaLink( rFile, rFilter, rOptions, rSource, aPos, 0/*nRefresh*/, false, false );
2684}
2685
2686void ScViewFunc::InsertTableLink( const OUString& rFile,
2687 const OUString& rFilter, const OUString& rOptions,
2688 std::u16string_view rTabName )
2689{
2690 OUString aFilterName = rFilter;
2691 OUString aOpt = rOptions;
2692 ScDocumentLoader aLoader( rFile, aFilterName, aOpt );
2693 if (aLoader.IsError())
2694 return;
2695
2696 ScDocShell* pSrcSh = aLoader.GetDocShell();
2697 ScDocument& rSrcDoc = pSrcSh->GetDocument();
2698 SCTAB nTab = MAXTAB+1;
2699 if (rTabName.empty()) // no name given -> first table
2700 nTab = 0;
2701 else
2702 {
2703 OUString aTemp;
2704 SCTAB nCount = rSrcDoc.GetTableCount();
2705 for (SCTAB i=0; i<nCount; i++)
2706 {
2707 rSrcDoc.GetName( i, aTemp );
2708 if ( aTemp == rTabName )
2709 nTab = i;
2710 }
2711 }
2712
2713 if ( nTab <= MAXTAB )
2714 ImportTables( pSrcSh, 1, &nTab, true,
2715 GetViewData().GetTabNo() );
2716}
2717
2718// Copy/link tables from another document
2719
2721 SCTAB nCount, const SCTAB* pSrcTabs, bool bLink,SCTAB nTab )
2722{
2723 ScDocument& rSrcDoc = pSrcShell->GetDocument();
2724
2725 ScDocShell* pDocSh = GetViewData().GetDocShell();
2726 ScDocument& rDoc = pDocSh->GetDocument();
2727 bool bUndo(rDoc.IsUndoEnabled());
2728
2729 bool bError = false;
2730 bool bRefs = false;
2731 bool bName = false;
2732
2733 if (rSrcDoc.GetDrawLayer())
2734 pDocSh->MakeDrawLayer();
2735
2736 if (bUndo)
2737 rDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
2738
2739 SCTAB nInsCount = 0;
2740 SCTAB i;
2741 for( i=0; i<nCount; i++ )
2742 { // insert sheets first and update all references
2743 OUString aName;
2744 rSrcDoc.GetName( pSrcTabs[i], aName );
2745 rDoc.CreateValidTabName( aName );
2746 if ( !rDoc.InsertTab( nTab+i, aName ) )
2747 {
2748 bError = true; // total error
2749 break; // for
2750 }
2751 ++nInsCount;
2752 }
2753 for (i=0; i<nCount && !bError; i++)
2754 {
2755 SCTAB nSrcTab = pSrcTabs[i];
2756 SCTAB nDestTab1=nTab+i;
2757 sal_uLong nErrVal = pDocSh->TransferTab( *pSrcShell, nSrcTab, nDestTab1,
2758 false, false ); // no insert
2759
2760 switch (nErrVal)
2761 {
2762 case 0: // internal error or full of errors
2763 bError = true;
2764 break;
2765 case 2:
2766 bRefs = true;
2767 break;
2768 case 3:
2769 bName = true;
2770 break;
2771 case 4:
2772 bRefs = bName = true;
2773 break;
2774 }
2775
2776 }
2777
2778 if (bLink)
2779 {
2780 sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
2781
2782 SfxMedium* pMed = pSrcShell->GetMedium();
2783 OUString aFileName = pMed->GetName();
2784 OUString aFilterName;
2785 if (pMed->GetFilter())
2786 aFilterName = pMed->GetFilter()->GetFilterName();
2787 OUString aOptions = ScDocumentLoader::GetOptions(*pMed);
2788
2789 bool bWasThere = rDoc.HasLink( aFileName, aFilterName, aOptions );
2790
2791 sal_uLong nRefresh = 0;
2792 OUString aTabStr;
2793 for (i=0; i<nInsCount; i++)
2794 {
2795 rSrcDoc.GetName( pSrcTabs[i], aTabStr );
2796 rDoc.SetLink( nTab+i, ScLinkMode::NORMAL,
2797 aFileName, aFilterName, aOptions, aTabStr, nRefresh );
2798 }
2799
2800 if (!bWasThere) // Insert link only once per source document
2801 {
2802 ScTableLink* pLink = new ScTableLink( pDocSh, aFileName, aFilterName, aOptions, nRefresh );
2803 pLink->SetInCreate( true );
2804 pLinkManager->InsertFileLink( *pLink, sfx2::SvBaseLinkObjectType::ClientFile, aFileName, &aFilterName );
2805 pLink->Update();
2806 pLink->SetInCreate( false );
2807
2808 SfxBindings& rBindings = GetViewData().GetBindings();
2809 rBindings.Invalidate( SID_LINKS );
2810 }
2811 }
2812
2813 if (bUndo)
2814 {
2815 pDocSh->GetUndoManager()->AddUndoAction(
2816 std::make_unique<ScUndoImportTab>( pDocSh, nTab, nCount ) );
2817 }
2818
2819 for (i=0; i<nInsCount; i++)
2820 GetViewData().InsertTab(nTab);
2821 SetTabNo(nTab,true);
2822 pDocSh->PostPaint( 0,0,0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB,
2824
2825 SfxApplication* pSfxApp = SfxGetpApp();
2826 pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2827 pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
2828
2829 pDocSh->PostPaintExtras();
2830 pDocSh->PostPaintGridAll();
2831 pDocSh->SetDocumentModified();
2832
2833 if (bRefs)
2834 ErrorMessage(STR_ABSREFLOST);
2835 if (bName)
2836 ErrorMessage(STR_NAMECONFLICT);
2837}
2838
2839// Move/Copy table to another document
2840
2842 sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString* pNewTabName )
2843{
2845 ScDocShell* pDocShell = GetViewData().GetDocShell();
2846 ScDocShell* pDestShell = nullptr;
2847 ScTabViewShell* pDestViewSh = nullptr;
2848 bool bUndo (rDoc.IsUndoEnabled());
2849 bool bRename = pNewTabName && !pNewTabName->isEmpty();
2850
2851 bool bNewDoc = (nDestDocNo == SC_DOC_NEW);
2852 if ( bNewDoc )
2853 {
2854 nDestTab = 0; // firstly insert
2855
2856 // execute without SfxCallMode::RECORD, because already contained in move command
2857
2858 SfxStringItem aItem( SID_FILE_NAME, "private:factory/" + STRING_SCAPP );
2859 SfxStringItem aTarget( SID_TARGETNAME, "_blank" );
2860
2861 const SfxPoolItem* pRetItem = GetViewData().GetDispatcher().ExecuteList(
2862 SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON,
2863 { &aItem, &aTarget });
2864 if ( pRetItem )
2865 {
2866 if ( auto pObjectItem = dynamic_cast<const SfxObjectItem*>(pRetItem) )
2867 pDestShell = dynamic_cast<ScDocShell*>( pObjectItem->GetShell() );
2868 else if ( auto pViewFrameItem = dynamic_cast<const SfxViewFrameItem*>( pRetItem) )
2869 {
2870 SfxViewFrame* pFrm = pViewFrameItem->GetFrame();
2871 if (pFrm)
2872 pDestShell = dynamic_cast<ScDocShell*>( pFrm->GetObjectShell() );
2873 }
2874 if (pDestShell)
2875 pDestViewSh = pDestShell->GetBestViewShell();
2876 }
2877 }
2878 else
2879 pDestShell = ScDocShell::GetShellByNum( nDestDocNo );
2880
2881 if (!pDestShell)
2882 {
2883 OSL_FAIL("Destination document not found !!!");
2884 return;
2885 }
2886
2887 ScMarkData& rMark = GetViewData().GetMarkData();
2888 if (bRename && rMark.GetSelectCount() != 1)
2889 {
2890 // Custom sheet name is provided, but more than one sheet is selected.
2891 // We don't support this scenario at the moment.
2892 return;
2893 }
2894
2895 ScDocument& rDestDoc = pDestShell->GetDocument();
2896
2897 if (&rDestDoc != &rDoc)
2898 {
2899 if (bNewDoc)
2900 {
2901 while (rDestDoc.GetTableCount() > 1)
2902 rDestDoc.DeleteTab(0);
2903 rDestDoc.RenameTab( 0, "______42_____" );
2904 }
2905
2906 SCTAB nTabCount = rDoc.GetTableCount();
2907 SCTAB nTabSelCount = rMark.GetSelectCount();
2908
2909 vector<SCTAB> TheTabs;
2910
2911 for(SCTAB i=0; i<nTabCount; ++i)
2912 {
2913 if(rMark.GetTableSelect(i))
2914 {
2915 OUString aTabName;
2916 rDoc.GetName( i, aTabName);
2917 TheTabs.push_back(i);
2918 for(SCTAB j=i+1;j<nTabCount;j++)
2919 {
2920 if((!rDoc.IsVisible(j)) && rDoc.IsScenario(j))
2921 {
2922 rDoc.GetName( j, aTabName);
2923 TheTabs.push_back(j);
2924 i=j;
2925 }
2926 else break;
2927 }
2928 }
2929 }
2930
2932
2933 if (rDoc.GetDrawLayer())
2934 pDestShell->MakeDrawLayer();
2935
2936 if (!bNewDoc && bUndo)
2937 rDestDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
2938
2939 sal_uLong nErrVal =1;
2940 if(nDestTab==SC_TAB_APPEND)
2941 nDestTab=rDestDoc.GetTableCount();
2942 SCTAB nDestTab1=nDestTab;
2943 ScClipParam aParam;
2944 for( size_t j=0; j<TheTabs.size(); ++j, ++nDestTab1 )
2945 { // insert sheets first and update all references
2946 OUString aName;
2947 if (bRename)
2948 aName = *pNewTabName;
2949 else
2950 rDoc.GetName( TheTabs[j], aName );
2951
2952 rDestDoc.CreateValidTabName( aName );
2953 if ( !rDestDoc.InsertTab( nDestTab1, aName ) )
2954 {
2955 nErrVal = 0; // total error
2956 break; // for
2957 }
2958 ScRange aRange( 0, 0, TheTabs[j], rDoc.MaxCol(), rDoc.MaxRow(), TheTabs[j] );
2959 aParam.maRanges.push_back(aRange);
2960 }
2961 rDoc.SetClipParam(aParam);
2962 if ( nErrVal > 0 )
2963 {
2964 nDestTab1 = nDestTab;
2965 for(SCTAB nTab : TheTabs)
2966 {
2967 nErrVal = pDestShell->TransferTab( *pDocShell, nTab, nDestTab1, false, false );
2968 nDestTab1++;
2969 }
2970 }
2971 if (!bNewDoc && bUndo)
2972 {
2973 OUString sName;
2974 rDestDoc.GetName(nDestTab, sName);
2975 pDestShell->GetUndoManager()->AddUndoAction(
2976 std::make_unique<ScUndoImportTab>( pDestShell, nDestTab,
2977 static_cast<SCTAB>(TheTabs.size())));
2978
2979 }
2980 else
2981 {
2982 pDestShell->GetUndoManager()->Clear();
2983 }
2984
2986 switch (nErrVal)
2987 {
2988 case 0: // internal error or full of errors
2989 {
2990 ErrorMessage(STR_TABINSERT_ERROR);
2991 return;
2992 }
2993 case 2:
2994 ErrorMessage(STR_ABSREFLOST);
2995 break;
2996 case 3:
2997 ErrorMessage(STR_NAMECONFLICT);
2998 break;
2999 case 4:
3000 {
3001 ErrorMessage(STR_ABSREFLOST);
3002 ErrorMessage(STR_NAMECONFLICT);
3003 }
3004 break;
3005 default:
3006 break;
3007 }
3008
3009 if (!bCopy)
3010 {
3011 if(nTabCount!=nTabSelCount)
3012 DeleteTables(TheTabs); // incl. Paint & Undo
3013 else
3014 ErrorMessage(STR_TABREMOVE_ERROR);
3015 }
3016
3017 if (bNewDoc)
3018 {
3019 // ChartListenerCollection must be updated before DeleteTab
3020 if ( rDestDoc.IsChartListenerCollectionNeedsUpdate() )
3022
3023 SCTAB nNumTabsInserted = static_cast<SCTAB>(TheTabs.size());
3024 pDestShell->Broadcast( ScTablesHint( SC_TABS_INSERTED, 0, nNumTabsInserted ) );
3025
3026 rDestDoc.DeleteTab( nNumTabsInserted ); // old first table
3027 pDestShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nNumTabsInserted ) );
3028
3029 if (pDestViewSh)
3030 {
3031 // Make sure to clear the cached page view after sheet
3032 // deletion, which still points to the sdr page belonging to
3033 // the deleted sheet.
3034 SdrView* pSdrView = pDestViewSh->GetScDrawView();
3035 if (pSdrView)
3036 pSdrView->ClearPageView();
3037
3038 pDestViewSh->TabChanged(); // pages on the drawing layer
3039 }
3040 pDestShell->PostPaint( 0,0,0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB,
3043 // PaintPartFlags::Size for outline
3044 }
3045 else
3046 {
3047 pDestShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, nDestTab ) );
3048 pDestShell->PostPaintExtras();
3049 pDestShell->PostPaintGridAll();
3050 }
3051
3052 TheTabs.clear();
3053
3054 pDestShell->SetDocumentModified();
3055 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3056 }
3057 else
3058 {
3059 // Move or copy within the same document.
3060 SCTAB nTabCount = rDoc.GetTableCount();
3061
3062 unique_ptr< vector<SCTAB> > pSrcTabs(new vector<SCTAB>);
3063 unique_ptr< vector<SCTAB> > pDestTabs(new vector<SCTAB>);
3064 unique_ptr< vector<OUString> > pTabNames(new vector<OUString>);
3065 unique_ptr< vector<OUString> > pDestNames;
3066 pSrcTabs->reserve(nTabCount);
3067 pDestTabs->reserve(nTabCount);
3068 pTabNames->reserve(nTabCount);
3069 OUString aDestName;
3070
3071 for(SCTAB i=0;i<nTabCount;i++)
3072 {
3073 if(rMark.GetTableSelect(i))
3074 {
3075 OUString aTabName;
3076 rDoc.GetName( i, aTabName);
3077 pTabNames->push_back(aTabName);
3078
3079 for(SCTAB j=i+1;j<nTabCount;j++)
3080 {
3081 if((!rDoc.IsVisible(j)) && rDoc.IsScenario(j))
3082 {
3083 rDoc.GetName( j, aTabName);
3084 pTabNames->push_back(aTabName);
3085 i=j;
3086 }
3087 else break;
3088 }
3089 }
3090 }
3091
3092 if (bCopy && bUndo)
3093 rDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
3094
3095 rDoc.GetName( nDestTab, aDestName);
3096 SCTAB nDestTab1=nDestTab;
3097 SCTAB nMovTab=0;
3098 for (size_t j = 0, n = pTabNames->size(); j < n; ++j)
3099 {
3100 nTabCount = rDoc.GetTableCount();
3101 const OUString& rStr = (*pTabNames)[j];
3102 if(!rDoc.GetTable(rStr,nMovTab))
3103 {
3104 nMovTab=nTabCount;
3105 }
3106 if(!rDoc.GetTable(aDestName,nDestTab1))
3107 {
3108 nDestTab1=nTabCount;
3109 }
3110 pDocShell->MoveTable( nMovTab, nDestTab1, bCopy, false ); // Undo is here
3111
3112 // tdf#43175 - Adjust chart references on every copied sheet
3113 if (bCopy)
3114 {
3115 // New position of source table after moving
3116 SCTAB nSrcTab = (nDestTab1 <= nMovTab) ? nMovTab + 1 : nMovTab;
3117 //#i29848# adjust references to data on the copied sheet
3119 nDestTab1);
3120 }
3121
3122 if(bCopy && rDoc.IsScenario(nMovTab))
3123 {
3124 OUString aComment;
3125 Color aColor;
3126 ScScenarioFlags nFlags;
3127
3128 rDoc.GetScenarioData(nMovTab, aComment,aColor, nFlags);
3129 rDoc.SetScenario(nDestTab1,true);
3130 rDoc.SetScenarioData(nDestTab1,aComment,aColor,nFlags);
3131 bool bActive = rDoc.IsActiveScenario(nMovTab );
3132 rDoc.SetActiveScenario( nDestTab1, bActive );
3133 bool bVisible=rDoc.IsVisible(nMovTab);
3134 rDoc.SetVisible(nDestTab1,bVisible );
3135 }
3136
3137 pSrcTabs->push_back(nMovTab);
3138
3139 if(!bCopy)
3140 {
3141 if(!rDoc.GetTable(rStr,nDestTab1))
3142 {
3143 nDestTab1=nTabCount;
3144 }
3145 }
3146
3147 pDestTabs->push_back(nDestTab1);
3148 }
3149
3150 // Rename must be done after all sheets have been moved.
3151 if (bRename)
3152 {
3153 pDestNames.reset(new vector<OUString>);
3154 size_t n = pDestTabs->size();
3155 pDestNames->reserve(n);
3156 for (size_t j = 0; j < n; ++j)
3157 {
3158 SCTAB nRenameTab = (*pDestTabs)[j];
3159 OUString aTabName = *pNewTabName;
3160 rDoc.CreateValidTabName( aTabName );
3161 pDestNames->push_back(aTabName);
3162 rDoc.RenameTab(nRenameTab, aTabName);
3163 }
3164 }
3165 else
3166 // No need to keep this around when we are not renaming.
3167 pTabNames.reset();
3168
3169 SCTAB nTab = GetViewData().GetTabNo();
3170
3171 if (bUndo)
3172 {
3173 if (bCopy)
3174 {
3175 pDocShell->GetUndoManager()->AddUndoAction(
3176 std::make_unique<ScUndoCopyTab>(
3177 pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pDestNames)));
3178 }
3179 else
3180 {
3181 pDocShell->GetUndoManager()->AddUndoAction(
3182 std::make_unique<ScUndoMoveTab>(
3183 pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pTabNames), std::move(pDestNames)));
3184 }
3185 }
3186
3187 SCTAB nNewTab = nDestTab;
3188 if (nNewTab == SC_TAB_APPEND)
3189 nNewTab = rDoc.GetTableCount()-1;
3190 else if (!bCopy && nTab<nDestTab)
3191 nNewTab--;
3192
3193 SetTabNo( nNewTab, true );
3194 }
3195}
3196
3197void ScViewFunc::ShowTable( const std::vector<OUString>& rNames )
3198{
3199 ScDocShell* pDocSh = GetViewData().GetDocShell();
3200 ScDocument& rDoc = pDocSh->GetDocument();
3201 bool bUndo(rDoc.IsUndoEnabled());
3202
3203 std::vector<SCTAB> undoTabs;
3204 SCTAB nPos = 0;
3205
3206 bool bFound(false);
3207
3208 for (const OUString& aName : rNames)
3209 {
3210 if (rDoc.GetTable(aName, nPos))
3211 {
3212 rDoc.SetVisible( nPos, true );
3213 SetTabNo( nPos, true );
3214 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3215 if (!bFound)
3216 bFound = true;
3217 if (bUndo)
3218 undoTabs.push_back(nPos);
3219 }
3220 }
3221 if (bFound)
3222 {
3223 if (bUndo)
3224 {
3225 pDocSh->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoShowHideTab>( pDocSh, std::move(undoTabs), true ) );
3226 }
3227 pDocSh->PostPaint(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB, PaintPartFlags::Extras);
3228 pDocSh->SetDocumentModified();
3229 }
3230}
3231
3232void ScViewFunc::HideTable( const ScMarkData& rMark, SCTAB nTabToSelect )
3233{
3234 ScDocShell* pDocSh = GetViewData().GetDocShell();
3235 ScDocument& rDoc = pDocSh->GetDocument();
3236 bool bUndo(rDoc.IsUndoEnabled());
3237 SCTAB nVisible = 0;
3238 SCTAB nTabCount = rDoc.GetTableCount();
3239
3240 SCTAB nTabSelCount = rMark.GetSelectCount();
3241
3242 // check to make sure we won't hide all sheets. we need at least one visible at all times.
3243 for ( SCTAB i=0; i < nTabCount && nVisible <= nTabSelCount ; i++ )
3244 if (rDoc.IsVisible(i))
3245 ++nVisible;
3246
3247 if (nVisible <= nTabSelCount)
3248 return;
3249
3250 std::vector<SCTAB> undoTabs;
3251
3252 // need to take a copy of selectedtabs since it is modified in the loop
3253 const ScMarkData::MarkedTabsType selectedTabs = rMark.GetSelectedTabs();
3254 for (const SCTAB& nTab : selectedTabs)
3255 {
3256 if (rDoc.IsVisible( nTab ))
3257 {
3258 rDoc.SetVisible( nTab, false );
3259 // Update views
3260 pDocSh->Broadcast( ScTablesHint( SC_TAB_HIDDEN, nTab ) );
3261 SetTabNo( nTab, true );
3262 // Store for undo
3263 if (bUndo)
3264 undoTabs.push_back(nTab);
3265 }
3266 }
3267
3268 if (nTabToSelect != -1)
3269 SetTabNo(nTabToSelect);
3270
3271 if (bUndo)
3272 {
3273 pDocSh->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoShowHideTab>( pDocSh, std::move(undoTabs), false ) );
3274 }
3275
3276 // Update views
3277 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3278 pDocSh->PostPaint(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB, PaintPartFlags::Extras);
3279 pDocSh->SetDocumentModified();
3280}
3281
3282void ScViewFunc::InsertSpecialChar( const OUString& rStr, const vcl::Font& rFont )
3283{
3284 ScEditableTester aTester( this );
3285 if (!aTester.IsEditable())
3286 {
3287 ErrorMessage(aTester.GetMessageId());
3288 return;
3289 }
3290
3291 const sal_Unicode* pChar = rStr.getStr();
3292 ScTabViewShell* pViewShell = GetViewData().GetViewShell();
3293 SvxFontItem aFontItem( rFont.GetFamilyType(),
3294 rFont.GetFamilyName(),
3295 rFont.GetStyleName(),
3296 rFont.GetPitch(),
3297 rFont.GetCharSet(),
3298 ATTR_FONT );
3299
3300 // if string contains WEAK characters, set all fonts
3301 SvtScriptType nScript;
3303 if ( rDoc.HasStringWeakCharacters( rStr ) )
3304 nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
3305 else
3306 nScript = rDoc.GetStringScriptType( rStr );
3307
3308 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, pViewShell->GetPool() );
3309 aSetItem.PutItemForScriptType( nScript, aFontItem );
3310 ApplyUserItemSet( aSetItem.GetItemSet() );
3311
3312 while ( *pChar )
3313 pViewShell->TabKeyInput( KeyEvent( *(pChar++), vcl::KeyCode() ) );
3314}
3315
3316void ScViewFunc::UpdateLineAttrs( SvxBorderLine& rLine,
3317 const SvxBorderLine* pDestLine,
3318 const SvxBorderLine* pSrcLine,
3319 bool bColor )
3320{
3321 if ( !(pSrcLine && pDestLine) )
3322 return;
3323
3324 if ( bColor )
3325 {
3326 rLine.SetColor ( pSrcLine->GetColor() );
3327 rLine.SetBorderLineStyle(pDestLine->GetBorderLineStyle());
3328 rLine.SetWidth ( pDestLine->GetWidth() );
3329 }
3330 else
3331 {
3332 rLine.SetColor ( pDestLine->GetColor() );
3333 rLine.SetBorderLineStyle(pSrcLine->GetBorderLineStyle());
3334 rLine.SetWidth ( pSrcLine->GetWidth() );
3335 }
3336}
3337
3338#define SET_LINE_ATTRIBUTES(LINE,BOXLINE) \
3339 pBoxLine = aBoxItem.Get##LINE(); \
3340 if ( pBoxLine ) \
3341 { \
3342 if ( pLine ) \
3343 { \
3344 UpdateLineAttrs( aLine, pBoxLine, pLine, bColorOnly ); \
3345 aBoxItem.SetLine( &aLine, BOXLINE ); \
3346 } \
3347 else \
3348 aBoxItem.SetLine( nullptr, BOXLINE ); \
3349 }
3350
3351void ScViewFunc::SetSelectionFrameLines( const SvxBorderLine* pLine,
3352 bool bColorOnly )
3353{
3354 // Not editable only due to a matrix? Attribute is ok anyhow.
3355 bool bOnlyNotBecauseOfMatrix;
3356 if ( !SelectionEditable( &bOnlyNotBecauseOfMatrix ) && !bOnlyNotBecauseOfMatrix )
3357 {
3358 ErrorMessage(STR_PROTECTIONERR);
3359 return;
3360 }
3361
3363 ScMarkData aFuncMark( GetViewData().GetMarkData() ); // local copy for UnmarkFiltered
3364 ScViewUtil::UnmarkFiltered( aFuncMark, rDoc );
3365 ScDocShell* pDocSh = GetViewData().GetDocShell();
3366 const ScPatternAttr* pSelAttrs = GetSelectionPattern();
3367 const SfxItemSet& rSelItemSet = pSelAttrs->GetItemSet();
3368
3369 const SfxPoolItem* pBorderAttr = nullptr;
3370 SfxItemState eItemState = rSelItemSet.GetItemState( ATTR_BORDER, true, &pBorderAttr );
3371
3372 const SfxPoolItem* pTLBRItem = nullptr;
3373 SfxItemState eTLBRState = rSelItemSet.GetItemState( ATTR_BORDER_TLBR, true, &pTLBRItem );
3374
3375 const SfxPoolItem* pBLTRItem = nullptr;
3376 SfxItemState eBLTRState = rSelItemSet.GetItemState( ATTR_BORDER_BLTR, true, &pBLTRItem );
3377
3378 // any of the lines visible?
3379 if( !((eItemState != SfxItemState::DEFAULT) || (eTLBRState != SfxItemState::DEFAULT) || (eBLTRState != SfxItemState::DEFAULT)) )
3380 return;
3381
3382 // none of the lines don't care?
3383 if( (eItemState != SfxItemState::DONTCARE) && (eTLBRState != SfxItemState::DONTCARE) && (eBLTRState != SfxItemState::DONTCARE) )
3384 {
3387
3388 SvxBorderLine aLine;
3389
3390 if( pBorderAttr )
3391 {
3392 const SvxBorderLine* pBoxLine = nullptr;
3393 SvxBoxItem aBoxItem( *static_cast<const SvxBoxItem*>(pBorderAttr) );
3394 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
3395
3396 // here pBoxLine is used
3397 SET_LINE_ATTRIBUTES(Top,SvxBoxItemLine::TOP)
3398 SET_LINE_ATTRIBUTES(Bottom,SvxBoxItemLine::BOTTOM)
3399 SET_LINE_ATTRIBUTES(Left,SvxBoxItemLine::LEFT)
3400 SET_LINE_ATTRIBUTES(Right,SvxBoxItemLine::RIGHT)
3401
3402 aBoxInfoItem.SetLine( aBoxItem.GetTop(), SvxBoxInfoItemLine::HORI );
3403 aBoxInfoItem.SetLine( aBoxItem.GetLeft(), SvxBoxInfoItemLine::VERT );
3404 aBoxInfoItem.ResetFlags(); // set Lines to Valid
3405
3406 aOldSet.Put( *pBorderAttr );
3407 aNewSet.Put( aBoxItem );
3408 aNewSet.Put( aBoxInfoItem );
3409 }
3410
3411 if( pTLBRItem && static_cast<const SvxLineItem*>(pTLBRItem)->GetLine() )
3412 {
3413 SvxLineItem aTLBRItem( *static_cast<const SvxLineItem*>(pTLBRItem) );
3414 UpdateLineAttrs( aLine, aTLBRItem.GetLine(), pLine, bColorOnly );
3415 aTLBRItem.SetLine( &aLine );
3416 aOldSet.Put( *pTLBRItem );
3417 aNewSet.Put( aTLBRItem );
3418 }
3419
3420 if( pBLTRItem && static_cast<const SvxLineItem*>(pBLTRItem)->GetLine() )
3421 {
3422 SvxLineItem aBLTRItem( *static_cast<const SvxLineItem*>(pBLTRItem) );
3423 UpdateLineAttrs( aLine, aBLTRItem.GetLine(), pLine, bColorOnly );
3424 aBLTRItem.SetLine( &aLine );
3425 aOldSet.Put( *pBLTRItem );
3426 aNewSet.Put( aBLTRItem );
3427 }
3428
3429 ApplyAttributes( &aNewSet, &aOldSet );
3430 }
3431 else // if ( eItemState == SfxItemState::DONTCARE )
3432 {
3433 aFuncMark.MarkToMulti();
3434 rDoc.ApplySelectionLineStyle( aFuncMark, pLine, bColorOnly );
3435 }
3436
3437 const ScRange& aMarkRange = aFuncMark.GetMultiMarkArea();
3438 SCCOL nStartCol = aMarkRange.aStart.Col();
3439 SCROW nStartRow = aMarkRange.aStart.Row();
3440 SCTAB nStartTab = aMarkRange.aStart.Tab();
3441 SCCOL nEndCol = aMarkRange.aEnd.Col();
3442 SCROW nEndRow = aMarkRange.aEnd.Row();
3443 SCTAB nEndTab = aMarkRange.aEnd.Tab();
3444 pDocSh->PostPaint( nStartCol, nStartRow, nStartTab,
3445 nEndCol, nEndRow, nEndTab,
3447
3448 pDocSh->UpdateOle(GetViewData());
3449 pDocSh->SetDocumentModified();
3450}
3451
3452#undef SET_LINE_ATTRIBUTES
3453
3455{
3457 sal_uLong nIndex = rDoc.AddValidationEntry(rNew); // for it there is no Undo
3459
3460 ApplyAttr( aItem ); // with Paint and Undo...
3461}
3462
3463/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SCTAB MAXTAB
Definition: address.hxx:70
const SCTAB SC_TAB_APPEND
Definition: address.hxx:90
SfxApplication * SfxGetpApp()
@ Scenario
field button for datapilot
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
sal_uInt32 GetValue() const
OUString GetText(LineEnd eEnd=LINEEND_LF) const
SCTAB Tab() const
Definition: address.hxx:283
void SetCol(SCCOL nColP)
Definition: address.hxx:291
void IncCol(SCCOL nDelta=1)
Definition: address.hxx:316
SCROW Row() const
Definition: address.hxx:274
void SetRow(SCROW nRowP)
Definition: address.hxx:287
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
void IncRow(SCROW nDelta=1)
Definition: address.hxx:312
OUString GetColRowString() const
Create a human-readable string representation of the cell address.
Definition: address.cxx:2467
SCCOL Col() const
Definition: address.hxx:279
static void AdjustRangesOfChartsOnDestinationPage(const ScDocument &rSrcDoc, ScDocument &rDestDoc, const SCTAB nSrcTab, const SCTAB nDestTab)
bool AutoFormat(const ScRange &rRange, const ScMarkData *pTabMark, sal_uInt16 nFormatNo, bool bApi)
Definition: docfunc.cxx:4204
bool UnmergeCells(const ScRange &rRange, bool bRecord, ScUndoRemoveMerge *pUndoRemoveMerge)
Definition: docfunc.cxx:5049
bool SetTabBgColor(SCTAB nTab, const Color &rColor, bool bRecord, bool bApi)
Definition: docfunc.cxx:3533
bool TabOp(const ScRange &rRange, const ScMarkData *pTabMark, const ScTabOpParam &rParam, bool bRecord, bool bApi)
Definition: docfunc.cxx:4404
SC_DLLPUBLIC bool MergeCells(const ScCellMergeOption &rOption, bool bContents, bool bRecord, bool bApi, bool bEmptyMergedCells=false)
Definition: docfunc.cxx:4932
void InsertAreaLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, const OUString &rSource, const ScRange &rDestRange, sal_Int32 nRefreshDelaySeconds, bool bFitBlock, bool bApi)
Definition: docfunc.cxx:5513
void ConvertFormulaToValue(const ScRange &rRange, bool bInteraction)
Definition: docfunc.cxx:5726
bool DeleteTable(SCTAB nTab, bool bRecord)
Definition: docfunc.cxx:3321
bool FillSimple(const ScRange &rRange, const ScMarkData *pTabMark, FillDir eDir, bool bApi)
Definition: docfunc.cxx:4544
bool IsAutoSpell() const
Definition: docoptio.hxx:53
SCTAB MakeScenario(SCTAB nTab, const OUString &rName, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags, ScMarkData &rMark, bool bRecord=true)
Definition: docsh5.cxx:783
bool AdjustPrintZoom(const ScRange &rRange)
Definition: docsh4.cxx:1684
void PostPaintGridAll()
Definition: docsh3.cxx:183
void SetDocumentModified()
Definition: docsh.cxx:2959
void UseScenario(SCTAB nTab, const OUString &rName, bool bRecord=true)
Definition: docsh5.cxx:659
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
void PostDataChanged()
Definition: docsh3.cxx:93
ScDrawLayer * MakeDrawLayer()
Definition: docsh2.cxx:172
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
Definition: docsh4.cxx:2608
void PostPaintExtras()
Definition: docsh3.cxx:198
void UpdateOle(const ScViewData &rViewData, bool bSnapSize=false)
Definition: docsh6.cxx:152
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
bool MoveTable(SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRecord)
Definition: docsh5.cxx:900
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: docsh3.cxx:451
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2638
sal_uLong TransferTab(ScDocShell &rSrcDocShell, SCTAB nSrcPos, SCTAB nDestPos, bool bInsertNew, bool bNotifyAndPaint)
Definition: docsh5.cxx:853
void SetPrintZoom(SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages)
Definition: docsh4.cxx:1651
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2945
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:222
void UpdateLinks() override
Definition: docsh6.cxx:318
static OUString GetOptions(const SfxMedium &rMedium)
Definition: tablink.cxx:422
bool IsError() const
Definition: tablink.cxx:578
ScDocShell * GetDocShell()
Definition: tablink.hxx:90
SC_DLLPUBLIC bool InsertTab(SCTAB nPos, const OUString &rName, bool bExternalDocument=false, bool bUndoDeleteTab=false)
Definition: document.cxx:505
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:471
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:897
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4218
sc::MultiDataCellState HasMultipleDataCells(const ScRange &rRange) const
Check if the specified range contains either: 1) one non-empty cell, 2) more than one non-empty cells...
Definition: document10.cxx:41
void GetAutoFormatData(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScAutoFormatData &rData)
Definition: documen3.cxx:1202
SC_DLLPUBLIC void CreateValidTabNames(std::vector< OUString > &aNames, SCTAB nCount) const
Definition: document.cxx:440
SC_DLLPUBLIC OUString GetLinkTab(SCTAB nTab) const
Definition: documen3.cxx:532
SC_DLLPUBLIC const ScTableProtection * GetTabProtection(SCTAB nTab) const
Definition: documen3.cxx:1922
void UpdatePageBreaks(SCTAB nTab, const ScRange *pUserArea=nullptr)
Definition: document.cxx:6330
SC_DLLPUBLIC bool ExtendMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, SCTAB nTab, bool bRefresh=false)
Definition: document.cxx:5669
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:573
SC_DLLPUBLIC bool InsertTabs(SCTAB nPos, const std::vector< OUString > &rNames, bool bNamesValid=false)
Definition: document.cxx:593
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:448
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
Definition: document.cxx:262
bool HasStringWeakCharacters(const OUString &rString)
Definition: documen6.cxx:51
void BeginDrawUndo()
Definition: documen9.cxx:60
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1913
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:891
SC_DLLPUBLIC void SetScenarioData(SCTAB nTab, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: documen3.cxx:437
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:863
const ScSheetEvents * GetSheetEvents(SCTAB nTab) const
Definition: documen3.cxx:663
OUString GetLinkOpt(SCTAB nTab) const
Definition: documen3.cxx:525
SC_DLLPUBLIC bool SetOptimalHeight(sc::RowHeightContext &rCxt, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bApi)
Definition: document.cxx:4323
SC_DLLPUBLIC void AddPrintRange(SCTAB nTab, const ScRange &rNew)
Adds a new print ranges.
Definition: document.cxx:6418
void FillTabMarked(SCTAB nSrcTab, const ScMarkData &rMark, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: document.cxx:3354
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6163
void GetSearchAndReplaceStart(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow)
Definition: documen3.cxx:1216
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:892
SC_DLLPUBLIC void ClearPrintRanges(SCTAB nTab)
Removes all print ranges.
Definition: document.cxx:6412
bool HasLink(std::u16string_view rDoc, std::u16string_view rFilter, std::u16string_view rOptions) const
Definition: documen3.cxx:554
bool Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab, SCCOL nVCol, SCROW nVRow, SCTAB nVTab, const OUString &sValStr, double &nX)
(Goal Seek) Find a value of x that is a root of f(x)
Definition: documen4.cxx:72
SC_DLLPUBLIC void SetPrintEntireSheet(SCTAB nTab)
Marks the specified sheet to be printed completely.
Definition: document.cxx:6424
SC_DLLPUBLIC SvtScriptType GetStringScriptType(const OUString &rString)
Definition: documen6.cxx:76
SC_DLLPUBLIC void GetScenarioData(SCTAB nTab, OUString &rComment, Color &rColor, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:468
void FillTab(const ScRange &rSrcArea, const ScMarkData &rMark, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: document.cxx:3286
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:466
bool IsInVBAMode() const
Definition: document.cxx:6600
void ApplySelectionLineStyle(const ScMarkData &rMark, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: document.cxx:4952
SC_DLLPUBLIC bool HasData(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen5.cxx:529
bool SearchAndReplace(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow, SCTAB &rTab, const ScMarkData &rMark, ScRangeList &rMatchedRanges, OUString &rUndoStr, ScDocument *pUndoDoc=nullptr)
Definition: documen3.cxx:1310
SC_DLLPUBLIC void SetDrawPageSize(SCTAB nTab)
Definition: documen9.cxx:195
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1082
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:393
SC_DLLPUBLIC void SetRepeatRowRange(SCTAB nTab, std::optional< ScRange > oNew)
Definition: document.cxx:6436
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
Definition: documen3.cxx:504
SC_DLLPUBLIC bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, HasAttrFlags nMask) const
Definition: document.cxx:5271
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:1008
void UpdateScriptTypes(const ScAddress &rPos, SCCOL nColSize, SCROW nRowSize)
Definition: document10.cxx:337
void CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, InsertDeleteFlags nFlags, bool bMarked, ScDocument &rDestDoc, const ScMarkData *pMarks=nullptr, bool bColRowFlags=true)
Definition: document.cxx:2070
SC_DLLPUBLIC void ApplyPatternIfNumberformatIncompatible(const ScRange &rRange, const ScMarkData &rMark, const ScPatternAttr &rPattern, SvNumFormatType nNewType)
Definition: document.cxx:4865
void FindAreaPos(SCCOL &rCol, SCROW &rRow, SCTAB nTab, ScMoveDirection eDirection) const
Definition: document.cxx:6197
const OUString & GetCodeName() const
Definition: document.hxx:608
SC_DLLPUBLIC sal_uLong AddValidationEntry(const ScValidationData &rNew)
Definition: documen4.cxx:726
SC_DLLPUBLIC void ExtendOverlapped(SCCOL &rStartCol, SCROW &rStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5579
sal_uLong GetLinkRefreshDelay(SCTAB nTab) const
Definition: documen3.cxx:539
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
Definition: documen3.cxx:546
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:460
SC_DLLPUBLIC void SetActiveScenario(SCTAB nTab, bool bActive)
Definition: documen3.cxx:885
std::unique_ptr< ScPrintRangeSaver > CreatePrintRangeSaver() const
Definition: document.cxx:6442
SC_DLLPUBLIC bool IsEmptyData(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:6173
static bool IsEmptyCellSearch(const SvxSearchItem &rSearchItem)
Definition: documen3.cxx:1303
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:918
SC_DLLPUBLIC OUString GetLinkDoc(SCTAB nTab) const
Definition: documen3.cxx:511
bool IsLinked(SCTAB nTab) const
Definition: documen3.cxx:485
SC_DLLPUBLIC CellType GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:3788
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:996
bool IsBlockEmpty(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5398
SC_DLLPUBLIC bool DeleteTab(SCTAB nTab)
Definition: document.cxx:674
SC_DLLPUBLIC void SetRepeatColRange(SCTAB nTab, std::optional< ScRange > oNew)
Definition: document.cxx:6430
SC_DLLPUBLIC bool DeleteTabs(SCTAB nTab, SCTAB nSheets)
Definition: document.cxx:770
SC_DLLPUBLIC sfx2::LinkManager * GetLinkManager()
Definition: documen2.cxx:230
bool IsUndoEnabled() const
Definition: document.hxx:1591
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:215
OUString GetLinkFlt(SCTAB nTab) const
Definition: documen3.cxx:518
void SetClipParam(const ScClipParam &rParam)
Definition: document.cxx:2607
SC_DLLPUBLIC void SetScenario(SCTAB nTab, bool bFlag)
Definition: documen3.cxx:426
void RemoveManualBreaks(SCTAB nTab)
Definition: document.cxx:6336
bool IsChartListenerCollectionNeedsUpdate() const
Definition: document.hxx:2232
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4806
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1946
SC_DLLPUBLIC void SetVisible(SCTAB nTab, bool bVisible)
Definition: document.cxx:911
SC_DLLPUBLIC bool IsActiveScenario(SCTAB nTab) const
Definition: documen3.cxx:880
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:315
bool NeedsObject() const
Definition: editutil.hxx:102
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:616
bool IsEditable() const
Definition: editable.hxx:84
TranslateId GetMessageId() const
Definition: editable.cxx:152
ScTokenArray * GetCode()
static SC_DLLPUBLIC const SvxSearchItem & GetSearchItem()
Definition: global.cxx:223
const std::vector< editeng::MisspellRanges > * GetAutoSpellData(SCCOL nPosX, SCROW nPosY)
Definition: gridwin.cxx:5904
void SetCellSelectionPixel(int nType, int nPixelX, int nPixelY)
Update the cell selection according to what handles have been dragged.
Definition: gridwin4.cxx:1694
void ResetAutoSpellForContentChange()
Definition: gridwin.cxx:5890
void GetCellSelection(std::vector< tools::Rectangle > &rLogicRects)
Get the cell selection, coordinates are in logic units.
Definition: gridwin.cxx:6508
void SetAutoSpellData(SCCOL nPosX, SCROW nPosY, const std::vector< editeng::MisspellRanges > *pRanges)
Definition: gridwin.cxx:5896
bool InsideVisibleRange(SCCOL nPosX, SCROW nPosY)
Definition: gridwin.cxx:5915
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
const_iterator end() const
Definition: markdata.hxx:164
const ScRange & GetMultiMarkArea() const
Definition: markdata.hxx:84
void SelectTable(SCTAB nTab, bool bNew)
Definition: markdata.cxx:157
const ScRange & GetMarkArea() const
Definition: markdata.hxx:83
SCTAB GetFirstSelected() const
Definition: markdata.cxx:185
bool IsMultiMarked() const
Definition: markdata.hxx:81
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:372
SCTAB GetLastSelected() const
Definition: markdata.cxx:194
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:169
std::set< SCTAB > MarkedTabsType
Definition: markdata.hxx:45
void SetMultiMarkArea(const ScRange &rRange, bool bMark=true, bool bSetupMulti=false)
Definition: markdata.cxx:107
void ResetMark()
Definition: markdata.cxx:80
SCTAB GetSelectCount() const
Definition: markdata.cxx:180
void MarkToMulti()
Definition: markdata.cxx:209
bool IsMarked() const
Definition: markdata.hxx:80
void SetMarkArea(const ScRange &rRange)
Definition: markdata.cxx:92
const MarkedTabsType & GetSelectedTabs() const
Definition: markdata.hxx:97
const_iterator begin() const
Definition: markdata.hxx:163
std::vector< sc::ColRowSpan > GetMarkedRowSpans() const
Definition: markdata.cxx:464
void MarkToSimple()
Definition: markdata.cxx:222
ScMergeCellsOption GetMergeCellsOption() const
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1301
SfxItemSet & GetItemSet()
Definition: patattr.hxx:155
bool UpdatePages()
Definition: printfun.cxx:2426
bool empty() const
Definition: rangelst.hxx:88
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1137
size_t size() const
Definition: rangelst.hxx:89
void PutInOrder()
Definition: address.hxx:622
ScAddress aEnd
Definition: address.hxx:498
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1733
ScAddress aStart
Definition: address.hxx:497
OutputDevice * GetDevice() const
Definition: sizedev.hxx:40
double GetPPTY() const
Definition: sizedev.hxx:42
bool IsPrinter() const
Definition: sizedev.hxx:43
double GetPPTX() const
Definition: sizedev.hxx:41
static void notifyAllViewsSheetGeomInvalidation(const SfxViewShell *pForViewShell, bool bColumns, bool bRows, bool bSizes, bool bHidden, bool bFiltered, bool bGroups, SCTAB nCurrentTabIndex)
Emits a LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY for all views whose current tab is equal to nCurrentTa...
Definition: tabvwshc.cxx:568
static void notifyAllViewsHeaderInvalidation(const SfxViewShell *pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
Emits a LOK_CALLBACK_INVALIDATE_HEADER for all views whose current tab is equal to nCurrentTabIndex.
Definition: tabvwshc.cxx:510
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:666
bool TabKeyInput(const KeyEvent &rKEvt)
Definition: tabvwsh4.cxx:1212
void UpdatePageBreakData(bool bForcePaint=false)
Definition: tabview2.cxx:1479
void TabChanged(bool bSameTabButMoved=false)
Called after moving, copying, inserting or deleting a sheet.
Definition: tabview5.cxx:281
void AlignToCursor(SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, const ScSplitPos *pWhich=nullptr)
Definition: tabview3.cxx:920
void DoneBlockMode(bool bContinue=false)
Definition: tabview2.cxx:409
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1446
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1691
vcl::Window * GetFrameWin() const
Definition: tabview.hxx:583
void PaintArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScUpdateMode eMode=ScUpdateMode::All)
Definition: tabview3.cxx:2310
static void UpdateInputLine()
Definition: tabview3.cxx:3038
ScViewData & GetViewData()
Definition: tabview.hxx:333
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:887
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:363
void Unmark()
Definition: tabview3.cxx:1727
SC_DLLPUBLIC void CellContentChanged()
Definition: tabview3.cxx:513
ScDrawView * GetScDrawView()
Definition: tabview.hxx:341
void MarkDataChanged()
Definition: tabview3.cxx:1750
void InitOwnBlockMode(const ScRange &rMarkRange)
Definition: tabview2.cxx:332
void UpdateScrollBars(HeaderType eHeaderType=BOTH_HEADERS)
Definition: tabview4.cxx:390
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1802
static void UpdateSearchItemAddressForReplace(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow)
Replace behaves differently to the Search; adjust the rCol and rRow accordingly.
Definition: table6.cxx:552
virtual formula::FormulaToken * AddOpCode(OpCode eCode) override
Definition: token.cxx:2264
formula::FormulaToken * AddDoubleReference(const ScComplexRefData &rRef)
Definition: token.cxx:2281
bool GetAdjacentExtendOfOuterFuncRefs(SCCOLROW &nExtend, const ScAddress &rPos, ScDirection)
Determines the extent of direct adjacent references.
Definition: token.cxx:2336
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3135
const ScViewOptions & GetOptions() const
Definition: viewdata.hxx:554
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3141
const Fraction & GetZoomY() const
Definition: viewdata.hxx:460
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void InsertTab(SCTAB nTab)
Definition: viewdata.cxx:881
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
double GetPPTY() const
Definition: viewdata.hxx:469
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3157
void GetPosFromPixel(tools::Long nClickX, tools::Long nClickY, ScSplitPos eWhich, SCCOL &rPosX, SCROW &rPosY, bool bTestMerge=true, bool bRepair=false, SCTAB nForTab=-1)
Definition: viewdata.cxx:2780
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
Definition: viewdata.cxx:1181
Point GetScrPos(SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich, bool bAllowNeg=false, SCTAB nForTab=-1) const
Definition: viewdata.cxx:2375
const Fraction & GetZoomX() const
Definition: viewdata.hxx:459
ScAddress GetCurPos() const
Definition: viewdata.cxx:4127
double GetPPTX() const
Definition: viewdata.hxx:468
SfxBindings & GetBindings()
Definition: viewdata.cxx:3129
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOL GetCurX() const
Definition: viewdata.hxx:401
bool AutoSum(const ScRange &rRange, bool bSubTotal, bool bSetCursor, bool bContinue, const OpCode eCode)
Definition: viewfun2.cxx:622
void TabOp(const ScTabOpParam &rParam, bool bRecord=true)
Definition: viewfun2.cxx:2313
bool SelectionEditable(bool *pOnlyNotBecauseOfMatrix=nullptr)
Definition: viewfunc.cxx:261
bool AppendTable(const OUString &rName, bool bRecord=true)
Definition: viewfun2.cxx:2432
bool GetAutoSumArea(ScRangeList &rRangeList)
Definition: viewfun2.cxx:510
void RemoveManualBreaks()
Definition: viewfun2.cxx:1006
void FillTab(InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: viewfun2.cxx:1678
void AdjustPrintZoom()
Definition: viewfun2.cxx:1037
SC_DLLPUBLIC void FillSimple(FillDir eDir)
Definition: viewfun2.cxx:1397
bool RemoveMerge()
Definition: viewfun2.cxx:1347
void EnterData(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const EditTextObject *pData=nullptr, bool bMatrixExpand=false)
Definition: viewfunc.cxx:365
SC_DLLPUBLIC void DeletePageBreak(bool bColumn, bool bRecord=true, const ScAddress *pPos=nullptr, bool bSetModified=true)
Definition: viewfun2.cxx:989
void ApplyUserItemSet(const SfxItemSet &rItemSet)
Definition: viewfunc.cxx:1330
void SetPrintRanges(bool bEntireSheet, const OUString *pPrint, const OUString *pRepCol, const OUString *pRepRow, bool bAddPrint)
Definition: viewfun2.cxx:1045
void FillSeries(FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd, double fStart, double fStep, double fMax)
Definition: viewfun2.cxx:1446
void TransliterateText(TransliterationFlags nType)
Definition: viewfun2.cxx:1880
void CopyAutoSpellData(FillDir eDir, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount)
Definition: viewfun2.cxx:1517
void EnterAutoSum(const ScRangeList &rRangeList, bool bSubTotal, const ScAddress &rAddr, const OpCode eCode)
Definition: viewfun2.cxx:616
void SetSelectionFrameLines(const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: viewfun2.cxx:3351
void SetPrintZoom(sal_uInt16 nScale)
Definition: viewfun2.cxx:1030
SC_DLLPUBLIC void InsertPageBreak(bool bColumn, bool bRecord=true, const ScAddress *pPos=nullptr, bool bSetModified=true)
Definition: viewfun2.cxx:972
bool DeleteTables(const std::vector< SCTAB > &TheTabs, bool bRecord=true)
void InsertAreaLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, const OUString &rSource)
Definition: viewfun2.cxx:2673
void EnterValue(SCCOL nCol, SCROW nRow, SCTAB nTab, const double &rValue)
Definition: viewfunc.cxx:649
bool SetTabBgColor(const Color &rColor, SCTAB nTabNr)
Definition: viewfun2.cxx:2653
void ApplySelectionPattern(const ScPatternAttr &rAttr, bool bCursorOnly=false)
Definition: viewfunc.cxx:1163
void FillCrossDblClick()
Downward fill of selected cell(s) by double-clicking cross-hair cursor.
Definition: viewfun2.cxx:1758
SC_DLLPUBLIC void FillAuto(FillDir eDir, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount)
Definition: viewfun2.cxx:1469
void DeleteTable(SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2463
SC_DLLPUBLIC const ScPatternAttr * GetSelectionPattern()
Definition: viewfunc.cxx:884
void MakeScenario(const OUString &rName, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: viewfun2.cxx:2326
ScAutoFormatData * CreateAutoFormatData()
Definition: viewfun2.cxx:1901
void ImportTables(ScDocShell *pSrcShell, SCTAB nCount, const SCTAB *pSrcTabs, bool bLink, SCTAB nTab)
Definition: viewfun2.cxx:2720
void HideTable(const ScMarkData &rMark, SCTAB nTabToSelect=-1)
Definition: viewfun2.cxx:3232
bool MergeCells(bool bApi, bool &rDoContents, bool bCenter)
Definition: viewfun2.cxx:1181
bool AdjustBlockHeight(bool bPaint=true, ScMarkData *pMarkData=nullptr)
Definition: viewfun2.cxx:115
void ShowTable(const std::vector< OUString > &rNames)
Definition: viewfun2.cxx:3197
void Solve(const ScSolveParam &rParam)
Definition: viewfun2.cxx:2243
void AutoFormat(sal_uInt16 nFormatNo)
Definition: viewfun2.cxx:1922
void MoveTable(sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString *pNewTabName=nullptr)
Definition: viewfun2.cxx:2841
void InsertSpecialChar(const OUString &rStr, const vcl::Font &rFont)
Definition: viewfun2.cxx:3282
static void UpdateLineAttrs(::editeng::SvxBorderLine &rLine, const ::editeng::SvxBorderLine *pDestLine, const ::editeng::SvxBorderLine *pSrcLine, bool bColor)
Definition: viewfun2.cxx:3316
void EnterBlock(const OUString &rString, const EditTextObject *pData)
Definition: viewfun2.cxx:883
void InsertTables(std::vector< OUString > &aNames, SCTAB nTab, SCTAB nCount, bool bRecord=true)
Definition: viewfun2.cxx:2390
void ApplyAttr(const SfxPoolItem &rAttrItem, bool bAdjustBlockHeight=true)
Definition: viewfunc.cxx:1053
bool TestRemoveMerge()
Definition: viewfun2.cxx:1308
bool RenameTable(const OUString &rName, SCTAB nTabNr)
Definition: viewfun2.cxx:2640
void OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth)
Definition: viewfunc.cxx:1631
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmptyCells=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
Definition: viewfun3.cxx:872
bool SearchAndReplace(const SvxSearchItem *pSearchItem, bool bAddUndo, bool bIsApi)
Definition: viewfun2.cxx:1940
void ApplyAttributes(const SfxItemSet *pDialogSet, const SfxItemSet *pOldSet, bool bAdjustBlockHeight=true)
Definition: viewfunc.cxx:941
void InsertTableLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, std::u16string_view rTabName)
Definition: viewfun2.cxx:2686
bool TestMergeCells()
Definition: viewfun2.cxx:1164
void ConvertFormulaToValue()
Definition: viewfun2.cxx:1869
void ExtendScenario()
Definition: viewfun2.cxx:2347
bool InsertTable(const OUString &rName, SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2377
OUString GetAutoSumFormula(const ScRangeList &rRangeList, bool bSubTotal, const ScAddress &rAddr, const OpCode eCode)
Definition: viewfun2.cxx:842
void SetValidation(const ScValidationData &rNew)
Definition: viewfun2.cxx:3454
void UseScenario(const OUString &rName)
Definition: viewfun2.cxx:2365
bool AdjustRowHeight(SCROW nStartRow, SCROW nEndRow, bool bApi)
Definition: viewfun2.cxx:193
bool GetOption(ScViewOption eOpt) const
Definition: viewopti.hxx:88
static void UnmarkFiltered(ScMarkData &rMark, const ScDocument &rDoc)
Definition: viewutil.cxx:223
virtual void ClearPageView() override
void Invalidate(sal_uInt16 nId)
std::shared_ptr< SfxDialogController > & GetController()
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const std::shared_ptr< const SfxFilter > & GetFilter() const
const OUString & GetName() const
SfxMedium * GetMedium() const
void SetWhich(sal_uInt16 nId)
SfxItemPool & GetPool() const
virtual void Clear()
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
static SfxViewFrame * Current()
SfxChildWindow * GetChildWindow(sal_uInt16)
SfxFrame & GetFrame() const
virtual SfxObjectShell * GetObjectShell() override
void ShowChildWindow(sal_uInt16, bool bVisible=true)
void setTiledSearching(bool bTiledSearching)
virtual void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
SvNumFormatType GetType(sal_uInt32 nFIndex) const
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxInfoItemLine nLine)
const editeng::SvxBorderLine * GetTop() const
const editeng::SvxBorderLine * GetLeft() const
const editeng::SvxBorderLine * GetLine() const
void SetLine(const editeng::SvxBorderLine *pNew)
void PutItemForScriptType(SvtScriptType nScriptType, const SfxPoolItem &rItem)
static void SetSearchLabel(const SearchLabel &rSL)
bool HasStartPoint() const
const OUString & GetSearchString() const
SvxSearchCmd GetCommand() const
const OUString & GetReplaceString() const
bool IsAllTables() const
void SetCommand(SvxSearchCmd nNewCommand)
SvxSearchCellType GetCellType() const
sal_Int32 GetStartPointX() const
bool GetBackward() const
sal_Int32 GetStartPointY() const
static UITestLogger & getInstance()
void logEvent(const EventDescription &rDescription)
static sal_Unicode GetNativeSymbolChar(OpCode eOp)
void CreateStringFromTokenArray(OUString &rFormula)
OpCode GetOuterFuncOpCode() const
FormulaToken * AddDouble(double fVal)
void FillResults(ScDocument &rDoc, const ScRangeList &rMatchedRanges, bool bCellNotes, bool bEmptyCells)
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
std::string extractAsStdString()
T * get() const
FontFamily GetFamilyType()
const OUString & GetStyleName() const
const OUString & GetFamilyName() const
FontPitch GetPitch()
rtl_TextEncoding GetCharSet() const
void LeaveWait()
void EnterWait()
virtual short run()
int nCount
constexpr double nPPTX
constexpr double nPPTY
void VBA_DeleteModule(ScDocShell &rDocSh, const OUString &sModuleName)
Definition: docfunc.cxx:3240
#define SC_PF_TESTMERGE
Definition: docsh.hxx:77
#define SC_PF_LINES
Definition: docsh.hxx:76
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2715
#define SC_DOC_NEW
Definition: document.hxx:247
@ SCDOCMODE_CLIP
Definition: document.hxx:256
@ SCDOCMODE_UNDO
Definition: document.hxx:257
@ SC_MOVE_DOWN
Definition: global.hxx:328
CellType
Definition: global.hxx:270
@ CELLTYPE_EDIT
Definition: global.hxx:275
@ CELLTYPE_FORMULA
Definition: global.hxx:274
constexpr OUStringLiteral STRING_SCAPP
Definition: global.hxx:57
ScPasteFunc
Definition: global.hxx:179
@ INS_NONE
Definition: global.hxx:293
InsertDeleteFlags
Definition: global.hxx:148
@ ATTRIB
Internal use only (d&d undo): do not delete caption objects of cell notes.
FillDateCmd
Definition: global.hxx:332
ScScenarioFlags
Definition: global.hxx:224
ScDirection
Definition: global.hxx:341
@ DIR_LEFT
Definition: global.hxx:345
@ DIR_TOP
Definition: global.hxx:344
FillCmd
Definition: global.hxx:315
FillDir
Definition: global.hxx:307
@ FILL_TO_TOP
Definition: global.hxx:310
@ FILL_TO_RIGHT
Definition: global.hxx:309
@ FILL_TO_LEFT
Definition: global.hxx:311
@ FILL_TO_BOTTOM
Definition: global.hxx:308
sal_Int32 nIndex
OUString aName
void * p
sal_Int64 n
SvtScriptType
sal_uInt16 nPos
SvBaseLink * pLink
@ MoveContentHiddenCells
@ EmptyContentHiddenCells
@ KeepContentHiddenCells
aBuf
std::unique_ptr< sal_Int32[]> pData
const char * sName
ScModelObj * getMustPropagateChangesModel(const ScDocShell &rDocShell)
Definition: docsh.hxx:475
void NotifyIfChangesListeners(const ScDocShell &rDocShell, const ScRange &rRange, const OUString &rType=OUString("cell-change"))
Definition: docsh.hxx:491
void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges, const OUString &rType=OUString("cell-change"), const css::uno::Sequence< css::beans::PropertyValue > &rProperties=css::uno::Sequence< css::beans::PropertyValue >())
Definition: docsh.hxx:483
int i
OpCode
ocStDev
ocClose
ocSubTotal
ocProduct
ocAverage
ocOpen
ocCount2
ocSep
ocVarP
ocStDevP
ocMin
ocVar
ocSum
ocCount
ocMax
SfxItemState
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_TLBR(141)
constexpr TypedWhichId< SvxBoxInfoItem > ATTR_BORDER_INNER(151)
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_BLTR(142)
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALIDDATA(153)
sal_uIntPtr sal_uLong
SvxSearchCmd
std::map< OUString, OUString > aParameters
ScRange getSingleRange(SCTAB nTab) const
::std::set< SCTAB > maTabs
ScRange getFirstSingleRange() const
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Definition: clipparam.hxx:31
ScRangeList maRanges
Definition: clipparam.hxx:34
Complex reference (a range) into the sheet.
Definition: refdata.hxx:123
void InitRangeRel(const ScDocument &rDoc, const ScRange &rRange, const ScAddress &rPos)
Definition: refdata.hxx:135
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:108
ScFormulaCell * getFormula() const
Definition: cellvalue.hxx:137
bool hasNumeric() const
Definition: cellvalue.cxx:619
CellType getType() const
Definition: cellvalue.hxx:133
SCCOL GetMaxColCount() const
Definition: sheetlimits.hxx:68
ScAddress aRefVariableCell
Definition: paramisc.hxx:28
std::optional< OUString > pStrTargetVal
Definition: paramisc.hxx:29
ScAddress aRefFormulaCell
Definition: paramisc.hxx:27
Parameter for data table aka multiple operations.
Definition: paramisc.hxx:46
::std::vector< ScUndoTabColorInfo > List
Definition: tabbgcolor.hxx:36
@ ROW_HEADER
Definition: tabview.hxx:60
bool bVisible
@ Left
Definition: tphfedit.hxx:40
@ Right
Definition: tphfedit.hxx:42
TransliterationFlags
sal_uInt16 sal_Unicode
signed char sal_Int8
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
#define SC_TABS_INSERTED
Definition: uiitems.hxx:80
#define SC_TAB_INSERTED
Definition: uiitems.hxx:75
#define SC_TAB_HIDDEN
Definition: uiitems.hxx:79
#define SC_TABS_DELETED
Definition: uiitems.hxx:81
#define SC_TAB_DELETED
Definition: uiitems.hxx:76
RET_OK
RET_CANCEL
RET_NO
RET_YES
@ SC_MARK_SIMPLE
Definition: viewdata.hxx:65
@ SC_FOLLOW_JUMP
Definition: viewdata.hxx:52
static ScAutoSum lcl_IsAutoSumData(ScDocument &rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, ScDirection eDir, SCCOLROW &nExtend)
Definition: viewfun2.cxx:271
static sal_Int8 GetSubTotal(const OpCode eCode)
Definition: viewfun2.cxx:477
#define SET_LINE_ATTRIBUTES(LINE, BOXLINE)
Definition: viewfun2.cxx:3338
static bool lcl_extendMergeRange(ScCellMergeOption &rOption, const ScRange &rRange)
Definition: viewfun2.cxx:1321
static bool lcl_FindNextSumEntryInColumn(ScDocument &rDoc, SCCOL nCol, SCROW &nRow, SCTAB nTab, SCCOLROW &nExtend, SCROW nMinRow)
Definition: viewfun2.cxx:353
#define SC_AUTOSUM_MAXCOUNT
Definition: viewfun2.cxx:320
static ScAutoSum lcl_SeekAutoSumData(ScDocument &rDoc, SCCOL &nCol, SCROW &nRow, SCTAB nTab, ScDirection eDir, SCCOLROW &nExtend)
Definition: viewfun2.cxx:322
static bool lcl_FindNextSumEntryInRow(ScDocument &rDoc, SCCOL &nCol, SCROW nRow, SCTAB nTab, SCCOLROW &nExtend, SCCOL nMinCol)
Definition: viewfun2.cxx:368
static ScAutoSum lcl_GetAutoSumForColumnRange(ScDocument &rDoc, ScRangeList &rRangeList, const ScRange &rRange)
Definition: viewfun2.cxx:383
static ScAutoSum lcl_GetAutoSumForRowRange(ScDocument &rDoc, ScRangeList &rRangeList, const ScRange &rRange)
Definition: viewfun2.cxx:430
@ VOPT_SUMMARY
Definition: viewopti.hxx:46
const char * pChar
SvNumFormatType