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 aBuf.insert(0, "=");
878 return aBuf.makeStringAndClear();
879}
880
881void ScViewFunc::EnterBlock( const OUString& rString, const EditTextObject* pData )
882{
883 // test for multi selection
884
885 SCCOL nCol = GetViewData().GetCurX();
886 SCROW nRow = GetViewData().GetCurY();
887 SCTAB nTab = GetViewData().GetTabNo();
889 if ( rMark.IsMultiMarked() )
890 {
891 rMark.MarkToSimple();
892 if ( rMark.IsMultiMarked() )
893 { // "Insert into multi selection not possible"
894 ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
895
896 // insert into single cell
897 if ( pData )
898 EnterData(nCol, nRow, nTab, *pData);
899 else
900 EnterData( nCol, nRow, nTab, rString );
901 return;
902 }
903 }
904
905 if (GetViewData().SelectionForbidsCellFill())
906 {
907 PaintArea(nCol, nRow, nCol, nRow); // possibly the edit-engine is still painted there
908 return;
909 }
910
912 OUString aNewStr = rString;
913 if ( pData )
914 {
915 const ScPatternAttr* pOldPattern = rDoc.GetPattern( nCol, nRow, nTab );
916 ScTabEditEngine aEngine( *pOldPattern, rDoc.GetEnginePool(), &rDoc );
918
919 ScEditAttrTester aTester( &aEngine );
920 if (!aTester.NeedsObject())
921 {
922 aNewStr = aEngine.GetText();
923 pData = nullptr;
924 }
925 }
926
927 // Insert via PasteFromClip
928 weld::WaitObject aWait(GetViewData().GetDialogParent());
929
930 ScAddress aPos( nCol, nRow, nTab );
931
933 pInsDoc->ResetClip( &rDoc, nTab );
934
935 if (aNewStr[0] == '=') // Formula ?
936 {
937 // SetString not possible, because in Clipboard-Documents nothing will be compiled!
938 pInsDoc->SetFormulaCell(aPos, new ScFormulaCell(rDoc, aPos, aNewStr));
939 }
940 else if ( pData )
941 {
942 // A copy of pData will be stored.
943 pInsDoc->SetEditText(aPos, *pData, rDoc.GetEditPool());
944 }
945 else
946 pInsDoc->SetString( nCol, nRow, nTab, aNewStr );
947
948 pInsDoc->SetClipArea( ScRange(aPos) );
949 // insert Block, with Undo etc.
950 if ( !PasteFromClip( InsertDeleteFlags::CONTENTS, pInsDoc.get(), ScPasteFunc::NONE, false, false,
952 return;
953
954 const SfxUInt32Item* pItem = pInsDoc->GetAttr(
955 nCol, nRow, nTab, ATTR_VALUE_FORMAT );
956 if ( pItem )
957 { // set number format if incompatible
958 // MarkData was already MarkToSimple'ed in PasteFromClip
959 const ScRange& aRange = rMark.GetMarkArea();
960 ScPatternAttr aPattern( rDoc.GetPool() );
961 aPattern.GetItemSet().Put( *pItem );
962 SvNumFormatType nNewType = rDoc.GetFormatTable()->GetType( pItem->GetValue() );
963 rDoc.ApplyPatternIfNumberformatIncompatible( aRange, rMark,
964 aPattern, nNewType );
965 }
966}
967
968// manual page break
969
970void ScViewFunc::InsertPageBreak( bool bColumn, bool bRecord, const ScAddress* pPos,
971 bool bSetModified )
972{
973 SCTAB nTab = GetViewData().GetTabNo();
974 ScAddress aCursor;
975 if (pPos)
976 aCursor = *pPos;
977 else
978 aCursor = ScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
979
980 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
981 InsertPageBreak( bColumn, aCursor, bRecord, bSetModified );
982
983 if ( bSuccess && bSetModified )
984 UpdatePageBreakData( true ); // for PageBreak-Mode
985}
986
987void ScViewFunc::DeletePageBreak( bool bColumn, bool bRecord, const ScAddress* pPos,
988 bool bSetModified )
989{
990 SCTAB nTab = GetViewData().GetTabNo();
991 ScAddress aCursor;
992 if (pPos)
993 aCursor = *pPos;
994 else
995 aCursor = ScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab );
996
997 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
998 RemovePageBreak( bColumn, aCursor, bRecord, bSetModified );
999
1000 if ( bSuccess && bSetModified )
1001 UpdatePageBreakData( true ); // for PageBreak-Mode
1002}
1003
1005{
1006 ScDocShell* pDocSh = GetViewData().GetDocShell();
1007 ScDocument& rDoc = pDocSh->GetDocument();
1008 SCTAB nTab = GetViewData().GetTabNo();
1009 bool bUndo(rDoc.IsUndoEnabled());
1010
1011 if (bUndo)
1012 {
1014 pUndoDoc->InitUndo( rDoc, nTab, nTab, true, true );
1015 rDoc.CopyToDocument( 0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, InsertDeleteFlags::NONE, false, *pUndoDoc );
1016 pDocSh->GetUndoManager()->AddUndoAction(
1017 std::make_unique<ScUndoRemoveBreaks>( pDocSh, nTab, std::move(pUndoDoc) ) );
1018 }
1019
1020 rDoc.RemoveManualBreaks(nTab);
1021 rDoc.UpdatePageBreaks(nTab);
1022
1023 UpdatePageBreakData( true );
1024 pDocSh->SetDocumentModified();
1025 pDocSh->PostPaint( 0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, PaintPartFlags::Grid );
1026}
1027
1028void ScViewFunc::SetPrintZoom(sal_uInt16 nScale)
1029{
1030 ScDocShell* pDocSh = GetViewData().GetDocShell();
1031 SCTAB nTab = GetViewData().GetTabNo();
1032 pDocSh->SetPrintZoom( nTab, nScale, 0/*nPages*/ );
1033}
1034
1036{
1037 ScRange aRange;
1038 if ( GetViewData().GetSimpleArea( aRange ) != SC_MARK_SIMPLE )
1041}
1042
1043void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint,
1044 const OUString* pRepCol, const OUString* pRepRow,
1045 bool bAddPrint )
1046{
1047 // on all selected tables
1048
1049 ScDocShell* pDocSh = GetViewData().GetDocShell();
1050 ScDocument& rDoc = pDocSh->GetDocument();
1051 ScMarkData& rMark = GetViewData().GetMarkData();
1052 bool bUndo (rDoc.IsUndoEnabled());
1053
1054 std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
1055
1056 ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0);
1057
1058 for (const SCTAB& nTab : rMark)
1059 {
1060 ScRange aRange( 0,0,nTab );
1061
1062 // print ranges
1063
1064 if( !bAddPrint )
1065 rDoc.ClearPrintRanges( nTab );
1066
1067 if( bEntireSheet )
1068 {
1069 rDoc.SetPrintEntireSheet( nTab );
1070 }
1071 else if ( pPrint )
1072 {
1073 if ( !pPrint->isEmpty() )
1074 {
1076 sal_Int32 nPos = 0;
1077 do
1078 {
1079 const OUString aToken = pPrint->getToken(0, sep, nPos);
1080 if ( aRange.ParseAny( aToken, rDoc, aDetails ) & ScRefFlags::VALID )
1081 rDoc.AddPrintRange( nTab, aRange );
1082 }
1083 while (nPos >= 0);
1084 }
1085 }
1086 else // NULL = use selection (print range is always set), use empty string to delete all ranges
1087 {
1088 if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
1089 {
1090 rDoc.AddPrintRange( nTab, aRange );
1091 }
1092 else if ( rMark.IsMultiMarked() )
1093 {
1094 rMark.MarkToMulti();
1095 ScRangeListRef pList( new ScRangeList );
1096 rMark.FillRangeListWithMarks( pList.get(), false );
1097 for (size_t i = 0, n = pList->size(); i < n; ++i)
1098 {
1099 const ScRange & rR = (*pList)[i];
1100 rDoc.AddPrintRange(nTab, rR);
1101 }
1102 }
1103 }
1104
1105 // repeat columns
1106
1107 if ( pRepCol )
1108 {
1109 if ( pRepCol->isEmpty() )
1110 rDoc.SetRepeatColRange( nTab, std::nullopt );
1111 else
1112 if ( aRange.ParseAny( *pRepCol, rDoc, aDetails ) & ScRefFlags::VALID )
1113 rDoc.SetRepeatColRange( nTab, std::move(aRange) );
1114 }
1115
1116 // repeat rows
1117
1118 if ( pRepRow )
1119 {
1120 if ( pRepRow->isEmpty() )
1121 rDoc.SetRepeatRowRange( nTab, std::nullopt );
1122 else
1123 if ( aRange.ParseAny( *pRepRow, rDoc, aDetails ) & ScRefFlags::VALID )
1124 rDoc.SetRepeatRowRange( nTab, std::move(aRange) );
1125 }
1126 }
1127
1128 // undo (for all tables)
1129 if (bUndo)
1130 {
1131 SCTAB nCurTab = GetViewData().GetTabNo();
1132 std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver();
1134 {
1135 tools::JsonWriter aJsonWriter;
1136 pNewRanges->GetPrintRangesInfo(aJsonWriter);
1137
1138 SfxViewShell* pViewShell = GetViewData().GetViewShell();
1139 const OString message = aJsonWriter.finishAndGetAsOString();
1140 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_PRINT_RANGES, message);
1141 }
1142
1143 pDocSh->GetUndoManager()->AddUndoAction(
1144 std::make_unique<ScUndoPrintRange>( pDocSh, nCurTab, std::move(pOldRanges), std::move(pNewRanges) ) );
1145 }
1146 else
1147 pOldRanges.reset();
1148
1149 // update page breaks
1150
1151 for (const auto& rTab : rMark)
1152 ScPrintFunc( pDocSh, pDocSh->GetPrinter(), rTab ).UpdatePages();
1153
1154 SfxBindings& rBindings = GetViewData().GetBindings();
1155 rBindings.Invalidate( SID_DELETE_PRINTAREA );
1156
1157 pDocSh->SetDocumentModified();
1158}
1159
1160// Merge cells
1161
1162bool ScViewFunc::TestMergeCells() // pre-test (for menu)
1163{
1164 // simple test: true if there's a selection but no multi selection and not filtered
1165
1166 const ScMarkData& rMark = GetViewData().GetMarkData();
1167 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
1168 {
1169 ScRange aRange;
1170 bool bMergeable = ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE );
1171 bMergeable = bMergeable && ( aRange.aStart.Col() != aRange.aEnd.Col() ||
1172 aRange.aStart.Row() != aRange.aEnd.Row() );
1173 return bMergeable;
1174 }
1175 else
1176 return false;
1177}
1178
1179bool ScViewFunc::MergeCells( bool bApi, bool& rDoContents, bool bCenter )
1180{
1181 // Editable- and Being-Nested- test must be at the beginning (in DocFunc too),
1182 // so that the Contents-QueryBox won't appear
1183 ScEditableTester aTester( this );
1184 if (!aTester.IsEditable())
1185 {
1186 ErrorMessage(aTester.GetMessageId());
1187 return false;
1188 }
1189
1190 ScMarkData& rMark = GetViewData().GetMarkData();
1191 rMark.MarkToSimple();
1192 if (!rMark.IsMarked())
1193 {
1194 ErrorMessage(STR_NOMULTISELECT);
1195 return false;
1196 }
1197
1198 ScDocShell* pDocSh = GetViewData().GetDocShell();
1199 ScDocument& rDoc = pDocSh->GetDocument();
1200
1201 const ScRange& aMarkRange = rMark.GetMarkArea();
1202 SCCOL nStartCol = aMarkRange.aStart.Col();
1203 SCROW nStartRow = aMarkRange.aStart.Row();
1204 SCTAB nStartTab = aMarkRange.aStart.Tab();
1205 SCCOL nEndCol = aMarkRange.aEnd.Col();
1206 SCROW nEndRow = aMarkRange.aEnd.Row();
1207 SCTAB nEndTab = aMarkRange.aEnd.Tab();
1208 if ( nStartCol == nEndCol && nStartRow == nEndRow )
1209 {
1210 // nothing to do
1211 return true;
1212 }
1213
1214 if ( rDoc.HasAttrib( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
1216 { // "Don't nest merging !"
1217 ErrorMessage(STR_MSSG_MERGECELLS_0);
1218 return false;
1219 }
1220
1221 // Check for the contents of all selected tables.
1222 bool bAskDialog = false;
1223 ScCellMergeOption aMergeOption(nStartCol, nStartRow, nEndCol, nEndRow, bCenter);
1224 for (const SCTAB& i : rMark)
1225 {
1226 aMergeOption.maTabs.insert(i);
1227
1228 sc::MultiDataCellState aState = rDoc.HasMultipleDataCells(aMergeOption.getSingleRange(i));
1229 switch (aState.meState)
1230 {
1232 {
1233 // this range contains multiple data cells.
1234 bAskDialog = true;
1235 break;
1236 }
1238 {
1239 // this range contains only one data cell.
1240 if (nStartCol != aState.mnCol1 || nStartRow != aState.mnRow1)
1241 rDoContents = true; // move the value to the top-left.
1242 break;
1243 }
1244 default:
1245 ;
1246 }
1247 }
1248
1249 bool bOk = true;
1250 bool bEmptyMergedCells = officecfg::Office::Calc::Compatibility::MergeCells::EmptyMergedCells::get();
1251
1252 if (bAskDialog)
1253 {
1254 bool bShowDialog = officecfg::Office::Calc::Compatibility::MergeCells::ShowDialog::get();
1255 if (!bApi && bShowDialog)
1256 {
1257 ScMergeCellsDialog aBox(GetViewData().GetDialogParent());
1258 sal_uInt16 nRetVal = aBox.run();
1259
1260 if ( nRetVal == RET_OK )
1261 {
1262 switch (aBox.GetMergeCellsOption())
1263 {
1265 rDoContents = true;
1266 break;
1268 bEmptyMergedCells = false;
1269 break;
1271 bEmptyMergedCells = true;
1272 break;
1273 default:
1274 assert(!"Unknown option for merge cells.");
1275 break;
1276 }
1277 }
1278 else if ( nRetVal == RET_CANCEL )
1279 bOk = false;
1280 }
1281 }
1282
1283 if (bOk)
1284 {
1285 bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, true/*bRecord*/, bApi, bEmptyMergedCells );
1286
1287 if (bOk)
1288 {
1289 SetCursor( nStartCol, nStartRow );
1290 //DoneBlockMode( sal_False);
1291 Unmark();
1292
1293 pDocSh->UpdateOle(GetViewData());
1295
1296 OUString aStartAddress = aMarkRange.aStart.GetColRowString();
1297 OUString aEndAddress = aMarkRange.aEnd.GetColRowString();
1298
1299 collectUIInformation({{"RANGE", aStartAddress + ":" + aEndAddress}}, "MERGE_CELLS");
1300 }
1301 }
1302
1303 return bOk;
1304}
1305
1307{
1308 bool bMerged = false;
1309 ScRange aRange;
1310 if (GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1311 {
1313 if ( rDoc.HasAttrib( aRange, HasAttrFlags::Merged ) )
1314 bMerged = true;
1315 }
1316 return bMerged;
1317}
1318
1319static bool lcl_extendMergeRange(ScCellMergeOption& rOption, const ScRange& rRange)
1320{
1321 bool bExtended = false;
1322 if (rOption.mnStartCol > rRange.aStart.Col())
1323 {
1324 rOption.mnStartCol = rRange.aStart.Col();
1325 bExtended = true;
1326 }
1327 if (rOption.mnStartRow > rRange.aStart.Row())
1328 {
1329 rOption.mnStartRow = rRange.aStart.Row();
1330 bExtended = true;
1331 }
1332 if (rOption.mnEndCol < rRange.aEnd.Col())
1333 {
1334 rOption.mnEndCol = rRange.aEnd.Col();
1335 bExtended = true;
1336 }
1337 if (rOption.mnEndRow < rRange.aEnd.Row())
1338 {
1339 rOption.mnEndRow = rRange.aEnd.Row();
1340 bExtended = true;
1341 }
1342 return bExtended;
1343}
1344
1346{
1347 ScRange aRange;
1348 ScEditableTester aTester( this );
1349 if (!aTester.IsEditable())
1350 {
1351 ErrorMessage(aTester.GetMessageId());
1352 return false;
1353 }
1354 else if (GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1355 {
1357 ScRange aExtended( aRange );
1358 rDoc.ExtendMerge( aExtended );
1359 ScDocShell* pDocSh = GetViewData().GetDocShell();
1360 const ScMarkData& rMark = GetViewData().GetMarkData();
1361 ScCellMergeOption aOption(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row());
1362 bool bExtended = false;
1363 do
1364 {
1365 bExtended = false;
1366 for (const SCTAB& i : rMark)
1367 {
1368 aOption.maTabs.insert(i);
1369 aExtended.aStart.SetTab(i);
1370 aExtended.aEnd.SetTab(i);
1371 rDoc.ExtendMerge(aExtended);
1372 rDoc.ExtendOverlapped(aExtended);
1373
1374 // Expand the current range to be inclusive of all merged
1375 // areas on all sheets.
1376 bExtended = lcl_extendMergeRange(aOption, aExtended);
1377 }
1378 }
1379 while (bExtended);
1380
1381 bool bOk = pDocSh->GetDocFunc().UnmergeCells(aOption, true/*bRecord*/, nullptr);
1382 aExtended = aOption.getFirstSingleRange();
1383 MarkRange( aExtended );
1384
1385 if (bOk)
1386 pDocSh->UpdateOle(GetViewData());
1387 }
1388
1389 OUString aCellLocation = aRange.aStart.GetColRowString();
1390 collectUIInformation({{"CELL", aCellLocation}}, "UNMERGE_CELL");
1391
1392 return true;
1393}
1394
1396{
1397 ScRange aRange;
1398 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1399 {
1400 ScDocShell* pDocSh = GetViewData().GetDocShell();
1401 const ScMarkData& rMark = GetViewData().GetMarkData();
1402 bool bSuccess = pDocSh->GetDocFunc().FillSimple( aRange, &rMark, eDir, false );
1403 if (bSuccess)
1404 {
1405 pDocSh->UpdateOle(GetViewData());
1407
1408 auto& rDoc = pDocSh->GetDocument();
1409 bool bDoAutoSpell = rDoc.GetDocOptions().IsAutoSpell();
1410 if ( bDoAutoSpell )
1411 {
1412 // Copy AutoSpellData from above(left/right/below) if no selection.
1413 switch (eDir)
1414 {
1415 case FILL_TO_BOTTOM:
1416 if (aRange.aStart.Row() > 0 && aRange.aStart.Row() == aRange.aEnd.Row())
1417 aRange.aStart.IncRow(-1);
1418 break;
1419 case FILL_TO_TOP:
1420 if (aRange.aEnd.Row() < rDoc.MaxRow() && aRange.aStart.Row() == aRange.aEnd.Row())
1421 aRange.aEnd.IncRow(1);
1422 break;
1423 case FILL_TO_RIGHT:
1424 if (aRange.aStart.Col() > 0 && aRange.aStart.Col() == aRange.aEnd.Col())
1425 aRange.aStart.IncCol(-1);
1426 break;
1427 case FILL_TO_LEFT:
1428 if (aRange.aEnd.Col() < rDoc.MaxCol() && aRange.aStart.Col() == aRange.aEnd.Col())
1429 aRange.aEnd.IncCol(1);
1430 break;
1431 }
1432 CopyAutoSpellData(eDir, aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(),
1433 ::std::numeric_limits<sal_uLong>::max());
1434 }
1435
1436 // Invalidate cell slots and update input line with new content.
1438 }
1439 }
1440 else
1441 ErrorMessage(STR_NOMULTISELECT);
1442}
1443
1445 double fStart, double fStep, double fMax )
1446{
1447 ScRange aRange;
1448 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1449 {
1450 ScDocShell* pDocSh = GetViewData().GetDocShell();
1451 const ScMarkData& rMark = GetViewData().GetMarkData();
1452 bool bSuccess = pDocSh->GetDocFunc().
1453 FillSeries( aRange, &rMark, eDir, eCmd, eDateCmd,
1454 fStart, fStep, fMax, false );
1455 if (bSuccess)
1456 {
1457 pDocSh->UpdateOle(GetViewData());
1459
1461 }
1462 }
1463 else
1464 ErrorMessage(STR_NOMULTISELECT);
1465}
1466
1467void ScViewFunc::FillAuto( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
1468 SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount )
1469{
1470 SCTAB nTab = GetViewData().GetTabNo();
1471 ScRange aRange( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab );
1472 ScRange aSourceRange( aRange );
1473 ScDocShell* pDocSh = GetViewData().GetDocShell();
1474 const ScMarkData& rMark = GetViewData().GetMarkData();
1475 bool bSuccess = pDocSh->GetDocFunc().
1476 FillAuto( aRange, &rMark, eDir, nCount, false );
1477 if (!bSuccess)
1478 return;
1479
1480 MarkRange( aRange, false ); // aRange was modified in FillAuto
1481 pDocSh->UpdateOle(GetViewData());
1483
1484 bool bDoAutoSpell = pDocSh->GetDocument().GetDocOptions().IsAutoSpell();
1485 if ( bDoAutoSpell )
1486 CopyAutoSpellData(eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount);
1487
1488 ScModelObj* pModelObj = pDocSh->GetModel();
1489
1490 ScRangeList aChangeRanges;
1491 ScRange aChangeRange( aRange );
1492 switch (eDir)
1493 {
1494 case FILL_TO_BOTTOM:
1495 aChangeRange.aStart.SetRow( aSourceRange.aEnd.Row() + 1 );
1496 break;
1497 case FILL_TO_TOP:
1498 aChangeRange.aEnd.SetRow( aSourceRange.aStart.Row() - 1 );
1499 break;
1500 case FILL_TO_RIGHT:
1501 aChangeRange.aStart.SetCol( aSourceRange.aEnd.Col() + 1 );
1502 break;
1503 case FILL_TO_LEFT:
1504 aChangeRange.aEnd.SetCol( aSourceRange.aStart.Col() - 1 );
1505 break;
1506 default:
1507 break;
1508 }
1509 aChangeRanges.push_back( aChangeRange );
1510
1512 HelperNotifyChanges::Notify(*pModelObj, aChangeRanges);
1513 else if (pModelObj)
1514 HelperNotifyChanges::Notify(*pModelObj, aChangeRanges, "data-area-invalidate");
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 // tdf#131326 - invalidate cell slots and update input line with new content
1879 pDocSh->PostPaint(aRange, PaintPartFlags::Grid);
1880}
1881
1883{
1884 ScMarkData aFuncMark = GetViewData().GetMarkData();
1885 if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
1886 {
1887 // no selection -> use cursor position
1888
1889 ScAddress aCursor( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
1890 aFuncMark.SetMarkArea( ScRange( aCursor ) );
1891 }
1892
1893 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
1894 TransliterateText( aFuncMark, nType, false );
1895 if (bSuccess)
1896 {
1898 }
1899}
1900
1901// AutoFormat
1902
1904{
1905 ScAutoFormatData* pData = nullptr;
1906 SCCOL nStartCol;
1907 SCROW nStartRow;
1908 SCTAB nStartTab;
1909 SCCOL nEndCol;
1910 SCROW nEndRow;
1911 SCTAB nEndTab;
1912 if (GetViewData().GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
1913 {
1914 if ( nEndCol-nStartCol >= 3 && nEndRow-nStartRow >= 3 )
1915 {
1917 pData = new ScAutoFormatData;
1918 rDoc.GetAutoFormatData( nStartTab, nStartCol,nStartRow,nEndCol,nEndRow, *pData );
1919 }
1920 }
1921 return pData;
1922}
1923
1924void ScViewFunc::AutoFormat( sal_uInt16 nFormatNo )
1925{
1926 ScRange aRange;
1927 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1928 {
1929 ScDocShell* pDocSh = GetViewData().GetDocShell();
1930 ScMarkData& rMark = GetViewData().GetMarkData();
1931
1932 bool bSuccess = pDocSh->GetDocFunc().AutoFormat( aRange, &rMark, nFormatNo, false );
1933 if (bSuccess)
1934 pDocSh->UpdateOle(GetViewData());
1935 }
1936 else
1937 ErrorMessage(STR_NOMULTISELECT);
1938}
1939
1940// Search & Replace
1941
1943 bool bAddUndo, bool bIsApi )
1944{
1945 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty);
1946 ScDocShell* pDocSh = GetViewData().GetDocShell();
1947 ScDocument& rDoc = pDocSh->GetDocument();
1948 ScMarkData& rMark = GetViewData().GetMarkData();
1949 if (bAddUndo && !rDoc.IsUndoEnabled())
1950 bAddUndo = false;
1951
1952 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() && (pSearchItem->HasStartPoint()) )
1953 {
1954 // No selection -> but we have a start point (top left corner of the
1955 // current view), start searching from there, not from the current
1956 // cursor position.
1957 SCCOL nPosX;
1958 SCROW nPosY;
1959
1960 int nPixelX = pSearchItem->GetStartPointX() * GetViewData().GetPPTX();
1961 int nPixelY = pSearchItem->GetStartPointY() * GetViewData().GetPPTY();
1962
1963 GetViewData().GetPosFromPixel(nPixelX, nPixelY, GetViewData().GetActivePart(), nPosX, nPosY);
1964
1965 AlignToCursor( nPosX, nPosY, SC_FOLLOW_JUMP );
1966 SetCursor( nPosX, nPosY, true );
1967 }
1968
1969 SCCOL nCol, nOldCol;
1970 SCROW nRow, nOldRow;
1971 SCTAB nTab, nOldTab;
1972 nCol = nOldCol = GetViewData().GetCurX();
1973 nRow = nOldRow = GetViewData().GetCurY();
1974 nTab = nOldTab = GetViewData().GetTabNo();
1975
1976 SvxSearchCmd nCommand = pSearchItem->GetCommand();
1977 bool bAllTables = pSearchItem->IsAllTables();
1978 std::set<SCTAB> aOldSelectedTables;
1979 SCTAB nLastTab = rDoc.GetTableCount() - 1;
1980 SCTAB nStartTab, nEndTab;
1981 if ( bAllTables )
1982 {
1983 nStartTab = 0;
1984 nEndTab = nLastTab;
1985 std::set<SCTAB> aTmp(rMark.begin(), rMark.end());
1986 aOldSelectedTables.swap(aTmp);
1987 }
1988 else
1989 {
1990 nStartTab = rMark.GetFirstSelected();
1991 nEndTab = rMark.GetLastSelected();
1992 }
1993
1994 if ( nCommand == SvxSearchCmd::FIND
1995 || nCommand == SvxSearchCmd::FIND_ALL)
1996 bAddUndo = false;
1997
1999
2000 ScDocumentUniquePtr pUndoDoc;
2001 std::unique_ptr<ScMarkData> pUndoMark;
2002 OUString aUndoStr;
2003 if (bAddUndo)
2004 {
2005 pUndoMark.reset(new ScMarkData(rMark)); // Mark is being modified
2006 if ( nCommand == SvxSearchCmd::REPLACE_ALL )
2007 {
2008 pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
2009 pUndoDoc->InitUndo( rDoc, nStartTab, nEndTab );
2010 }
2011 }
2012
2013 if ( bAllTables )
2014 {
2015 for ( SCTAB j = nStartTab; j <= nEndTab; j++ )
2016 {
2017 rMark.SelectTable( j, true );
2018 }
2019 }
2020
2021 DoneBlockMode(true); // don't delete mark
2022 InitOwnBlockMode( ScRange( nCol, nRow, nStartTab, nCol, nRow, nEndTab));
2023
2024 // If search starts at the beginning don't ask again whether it shall start at the beginning
2025 bool bFirst = true;
2026 if ( nCol == 0 && nRow == 0 && nTab == nStartTab && !pSearchItem->GetBackward() )
2027 bFirst = false;
2028
2029 bool bFound = false;
2030 while (true)
2031 {
2033 ScRangeList aMatchedRanges;
2034 bool bMatchedRangesWereClamped = false;
2035 if (rDoc.SearchAndReplace(*pSearchItem, nCol, nRow, nTab, rMark, aMatchedRanges, aUndoStr, pUndoDoc.get(), bMatchedRangesWereClamped))
2036 {
2037 bFound = true;
2038 if (bAddUndo)
2039 {
2041 std::make_unique<ScUndoReplace>( GetViewData().GetDocShell(), *pUndoMark,
2042 nCol, nRow, nTab,
2043 aUndoStr, std::move(pUndoDoc), pSearchItem ) );
2044 }
2045
2046 if (nCommand == SvxSearchCmd::FIND_ALL || nCommand == SvxSearchCmd::REPLACE_ALL)
2047 {
2048 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
2050
2051 if (bShow && pViewFrm && !comphelper::LibreOfficeKit::isActive())
2052 {
2053 pViewFrm->ShowChildWindow(sc::SearchResultsDlgWrapper::GetChildWindowId());
2054 SfxChildWindow* pWnd = pViewFrm->GetChildWindow(sc::SearchResultsDlgWrapper::GetChildWindowId());
2055 if (pWnd)
2056 {
2057 sc::SearchResultsDlg* pDlg = static_cast<sc::SearchResultsDlg*>(pWnd->GetController().get());
2058 if (pDlg)
2059 {
2060 const bool bCellNotes = (pSearchItem->GetCellType() == SvxSearchCellType::NOTE);
2061 // ScCellIterator iterates over cells with content,
2062 // for empty cells iterate over match positions.
2063 const bool bEmptyCells = (!bCellNotes
2064 && ((nCommand == SvxSearchCmd::FIND_ALL
2065 && ScDocument::IsEmptyCellSearch(*pSearchItem))
2066 || (nCommand == SvxSearchCmd::REPLACE_ALL
2067 && pSearchItem->GetReplaceString().isEmpty())));
2068 pDlg->FillResults(rDoc, aMatchedRanges, bCellNotes, bEmptyCells, bMatchedRangesWereClamped);
2069 }
2070 }
2071 }
2072
2073 rMark.ResetMark();
2074 for (size_t i = 0, n = aMatchedRanges.size(); i < n; ++i)
2075 {
2076 const ScRange& r = aMatchedRanges[i];
2077 if (r.aStart.Tab() == nTab)
2078 rMark.SetMultiMarkArea(r);
2079 }
2080 }
2081
2082 break; // break 'while (TRUE)'
2083 }
2084 else if ( bFirst && (nCommand == SvxSearchCmd::FIND ||
2085 nCommand == SvxSearchCmd::REPLACE) )
2086 {
2087 bFirst = false;
2089 if (!bIsApi)
2090 {
2091 if ( nStartTab == nEndTab )
2092 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::EndSheet);
2093 else
2095
2096 rDoc.GetSearchAndReplaceStart( *pSearchItem, nCol, nRow );
2097 if (pSearchItem->GetBackward())
2098 nTab = nEndTab;
2099 else
2100 nTab = nStartTab;
2101 }
2102 else
2103 {
2104 break; // break 'while (TRUE)'
2105 }
2106 }
2107 else // nothing found
2108 {
2109 if ( nCommand == SvxSearchCmd::FIND_ALL || nCommand == SvxSearchCmd::REPLACE_ALL )
2110 {
2111 pDocSh->PostPaintGridAll(); // Mark
2112 }
2113
2115 if (!bIsApi)
2116 {
2117 GetViewData().GetViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, pSearchItem->GetSearchString().toUtf8());
2118 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NotFound);
2119 }
2120
2121 break; // break 'while (TRUE)'
2122 }
2123 } // of while true
2124
2125 if (!aOldSelectedTables.empty())
2126 {
2127 // restore originally selected table
2128 for (SCTAB i = 0; i <= nEndTab; ++i)
2129 rMark.SelectTable(i, false);
2130
2131 for (const auto& rTab : aOldSelectedTables)
2132 rMark.SelectTable(rTab, true);
2133
2134 if ( bFound )
2135 { // if a table is selected as a "match" it remains selected.
2136 rMark.SelectTable( nTab, true );
2137 // It's a swap if only one table was selected before
2139 if ( aOldSelectedTables.size() == 1 && nTab != nOldTab )
2140 rMark.SelectTable( nOldTab, false );
2141 }
2142 }
2143
2144 // Avoid LOK selection notifications before we have all the results.
2148
2149 if ( bFound )
2150 {
2151 if ( nTab != GetViewData().GetTabNo() )
2152 SetTabNo( nTab );
2153
2154 // if nothing is marked, DoneBlockMode, then marking can start
2155 // directly from this place via Shift-Cursor
2156 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2157 DoneBlockMode(true);
2158
2159 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
2160 SetCursor( nCol, nRow, true );
2161
2163 {
2164 Point aCurPos = GetViewData().GetScrPos(nCol, nRow, GetViewData().GetActivePart());
2165
2166 // just update the cell selection
2167 ScGridWindow* pGridWindow = GetViewData().GetActiveWin();
2168 // Don't move cell selection handles for find-all: selection of all but the first result would be lost.
2169 if (pGridWindow && nCommand == SvxSearchCmd::FIND)
2170 {
2171 // move the cell selection handles
2172 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_RESET, aCurPos.X(), aCurPos.Y());
2173 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_START, aCurPos.X(), aCurPos.Y());
2174 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_END, aCurPos.X(), aCurPos.Y());
2175 }
2176
2177 if (pGridWindow)
2178 {
2179 std::vector<tools::Rectangle> aLogicRects;
2180 pGridWindow->GetCellSelection(aLogicRects);
2181
2182 boost::property_tree::ptree aTree;
2183 aTree.put("searchString", pSearchItem->GetSearchString().toUtf8().getStr());
2184 aTree.put("highlightAll", nCommand == SvxSearchCmd::FIND_ALL);
2185
2186 boost::property_tree::ptree aSelections;
2187 for (const tools::Rectangle& rLogicRect : aLogicRects)
2188 {
2189 boost::property_tree::ptree aSelection;
2190 aSelection.put("part", OString::number(nTab).getStr());
2191 aSelection.put("rectangles", rLogicRect.toString().getStr());
2192 aSelections.push_back(std::make_pair("", aSelection));
2193 }
2194 aTree.add_child("searchResultSelection", aSelections);
2195
2196 std::stringstream aStream;
2197 boost::property_tree::write_json(aStream, aTree);
2198 OString aPayload( aStream.str() );
2199 SfxViewShell* pViewShell = GetViewData().GetViewShell();
2200 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload);
2201
2202 // Trigger LOK_CALLBACK_TEXT_SELECTION now.
2204 }
2205 }
2206
2207 if ( nCommand == SvxSearchCmd::REPLACE
2208 || nCommand == SvxSearchCmd::REPLACE_ALL )
2209 {
2210 if ( nCommand == SvxSearchCmd::REPLACE )
2211 {
2212 pDocSh->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PaintPartFlags::Grid );
2213
2214 // jump to next cell if we replaced everything in the cell
2215 // where the cursor was positioned (but avoid switching tabs)
2216 if ( nCol == nOldCol && nRow == nOldRow && nTab == nOldTab )
2217 {
2218 SvxSearchItem aSearchItem = ScGlobal::GetSearchItem();
2219 aSearchItem.SetCommand(SvxSearchCmd::FIND);
2220 aSearchItem.SetWhich(SID_SEARCH_ITEM);
2221
2222 ScRangeList aMatchedRanges;
2223 bool bMatchedRangesWereClamped;
2224 ScTable::UpdateSearchItemAddressForReplace( aSearchItem, nCol, nRow );
2225 if ( rDoc.SearchAndReplace( aSearchItem, nCol, nRow, nTab, rMark, aMatchedRanges, aUndoStr, nullptr, bMatchedRangesWereClamped ) &&
2226 ( nTab == nOldTab ) &&
2227 ( nCol != nOldCol || nRow != nOldRow ) )
2228 {
2229 AlignToCursor(nCol, nRow, SC_FOLLOW_JUMP);
2230 SetCursor( nCol, nRow, true );
2231 }
2232 }
2233 }
2234 else
2235 pDocSh->PostPaintGridAll();
2236 pDocSh->SetDocumentModified();
2237 }
2238 else if ( nCommand == SvxSearchCmd::FIND_ALL )
2239 pDocSh->PostPaintGridAll(); // mark
2241 }
2242 return bFound;
2243}
2244
2245// Goal Seek
2246
2247void ScViewFunc::Solve( const ScSolveParam& rParam )
2248{
2250
2251 SCCOL nDestCol = rParam.aRefVariableCell.Col();
2252 SCROW nDestRow = rParam.aRefVariableCell.Row();
2253 SCTAB nDestTab = rParam.aRefVariableCell.Tab();
2254
2255 ScEditableTester aTester( rDoc, nDestTab, nDestCol,nDestRow, nDestCol,nDestRow );
2256 if (!aTester.IsEditable())
2257 {
2258 ErrorMessage(aTester.GetMessageId());
2259 return;
2260 }
2261
2262 OUString aTargetValStr;
2263 if ( rParam.pStrTargetVal )
2264 aTargetValStr = *rParam.pStrTargetVal;
2265
2266 OUString aMsgStr;
2267 OUString aResStr;
2268 double nSolveResult;
2269
2271
2272 bool bExact =
2273 rDoc.Solver(
2274 rParam.aRefFormulaCell.Col(),
2275 rParam.aRefFormulaCell.Row(),
2276 rParam.aRefFormulaCell.Tab(),
2277 nDestCol, nDestRow, nDestTab,
2278 aTargetValStr,
2279 nSolveResult );
2280
2282
2283 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
2284 sal_uLong nFormat = 0;
2285 const ScPatternAttr* pPattern = rDoc.GetPattern( nDestCol, nDestRow, nDestTab );
2286 if ( pPattern )
2287 nFormat = pPattern->GetNumberFormat( pFormatter );
2288 const Color* p;
2289 pFormatter->GetOutputString( nSolveResult, nFormat, aResStr, &p );
2290
2291 if ( bExact )
2292 {
2293 aMsgStr += ScResId( STR_MSSG_SOLVE_0 ) +
2294 aResStr +
2295 ScResId( STR_MSSG_SOLVE_1 );
2296 }
2297 else
2298 {
2299 aMsgStr = ScResId( STR_MSSG_SOLVE_2 ) +
2300 ScResId( STR_MSSG_SOLVE_3 ) +
2301 aResStr +
2302 ScResId( STR_MSSG_SOLVE_4 );
2303 }
2304
2305 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetViewData().GetDialogParent(),
2306 VclMessageType::Question, VclButtonsType::YesNo, aMsgStr));
2307 xBox->set_title(ScResId(STR_MSSG_DOSUBTOTALS_0));
2308 xBox->set_default_response(RET_NO);
2309 if (xBox->run() == RET_YES)
2310 EnterValue( nDestCol, nDestRow, nDestTab, nSolveResult );
2311
2313}
2314
2315// multi operation
2316
2317void ScViewFunc::TabOp( const ScTabOpParam& rParam, bool bRecord )
2318{
2319 ScRange aRange;
2320 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
2321 {
2322 ScDocShell* pDocSh = GetViewData().GetDocShell();
2323 ScMarkData& rMark = GetViewData().GetMarkData();
2324 pDocSh->GetDocFunc().TabOp( aRange, &rMark, rParam, bRecord, false );
2325 }
2326 else
2327 ErrorMessage(STR_NOMULTISELECT);
2328}
2329
2330void ScViewFunc::MakeScenario( const OUString& rName, const OUString& rComment,
2331 const Color& rColor, ScScenarioFlags nFlags )
2332{
2333 ScDocShell* pDocSh = GetViewData().GetDocShell();
2334 ScMarkData& rMark = GetViewData().GetMarkData();
2335 SCTAB nTab = GetViewData().GetTabNo();
2336
2337 SCTAB nNewTab = pDocSh->MakeScenario( nTab, rName, rComment, rColor, nFlags, rMark );
2338 if (nFlags & ScScenarioFlags::CopyAll)
2339 SetTabNo( nNewTab, true ); // ScScenarioFlags::CopyAll -> visible
2340 else
2341 {
2342 SfxBindings& rBindings = GetViewData().GetBindings();
2343 rBindings.Invalidate( SID_STATUS_DOCPOS ); // Statusbar
2344 rBindings.Invalidate( SID_ROWCOL_SELCOUNT ); // Statusbar
2345 rBindings.Invalidate( SID_TABLES_COUNT );
2346 rBindings.Invalidate( SID_SELECT_SCENARIO );
2347 rBindings.Invalidate( FID_TABLE_SHOW );
2348 }
2349}
2350
2352{
2353 ScEditableTester aTester( this );
2354 if (!aTester.IsEditable())
2355 {
2356 ErrorMessage(aTester.GetMessageId());
2357 return;
2358 }
2359
2360 // Undo: apply attributes
2361
2363 ScPatternAttr aPattern( rDoc.GetPool() );
2365 aPattern.GetItemSet().Put( ScProtectionAttr( true ) );
2366 ApplySelectionPattern(aPattern);
2367}
2368
2369void ScViewFunc::UseScenario( const OUString& rName )
2370{
2371 ScDocShell* pDocSh = GetViewData().GetDocShell();
2372 SCTAB nTab = GetViewData().GetTabNo();
2373
2374 DoneBlockMode();
2375 InitOwnBlockMode( ScRange( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab));
2376 pDocSh->UseScenario( nTab, rName );
2377}
2378
2379// Insert table
2380
2381bool ScViewFunc::InsertTable( const OUString& rName, SCTAB nTab, bool bRecord )
2382{
2383 // Order Table/Name is inverted for DocFunc
2384 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
2385 InsertTable( nTab, rName, bRecord, false );
2386 if (bSuccess)
2387 SetTabNo( nTab, true );
2388
2389 return bSuccess;
2390}
2391
2392// Insert tables
2393
2394void ScViewFunc::InsertTables(std::vector<OUString>& aNames, SCTAB nTab,
2395 SCTAB nCount, bool bRecord )
2396{
2397 ScDocShell* pDocSh = GetViewData().GetDocShell();
2398 ScDocument& rDoc = pDocSh->GetDocument();
2399 if (bRecord && !rDoc.IsUndoEnabled())
2400 bRecord = false;
2401
2402 weld::WaitObject aWait(GetViewData().GetDialogParent());
2403
2404 if (bRecord)
2405 {
2406 rDoc.BeginDrawUndo(); // InsertTab creates a SdrUndoNewPage
2407 }
2408
2409 bool bFlag=false;
2410
2411 if(aNames.empty())
2412 {
2413 rDoc.CreateValidTabNames(aNames, nCount);
2414 }
2415 if (rDoc.InsertTabs(nTab, aNames))
2416 {
2417 pDocSh->Broadcast( ScTablesHint( SC_TABS_INSERTED, nTab, nCount ) );
2418 bFlag = true;
2419 }
2420
2421 if (!bFlag)
2422 return;
2423
2424 if (bRecord)
2425 pDocSh->GetUndoManager()->AddUndoAction(
2426 std::make_unique<ScUndoInsertTables>( pDocSh, nTab, std::move(aNames)));
2427
2428 // Update views
2429
2430 SetTabNo( nTab, true );
2431 pDocSh->PostPaintExtras();
2432 pDocSh->SetDocumentModified();
2433 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2434}
2435
2436bool ScViewFunc::AppendTable( const OUString& rName, bool bRecord )
2437{
2438 ScDocShell* pDocSh = GetViewData().GetDocShell();
2439 ScDocument& rDoc = pDocSh->GetDocument();
2440 if (bRecord && !rDoc.IsUndoEnabled())
2441 bRecord = false;
2442
2443 weld::WaitObject aWait(GetViewData().GetDialogParent());
2444
2445 if (bRecord)
2446 rDoc.BeginDrawUndo(); // InsertTab creates a SdrUndoNewPage
2447
2448 if (rDoc.InsertTab( SC_TAB_APPEND, rName ))
2449 {
2450 SCTAB nTab = rDoc.GetTableCount()-1;
2451 if (bRecord)
2452 pDocSh->GetUndoManager()->AddUndoAction(
2453 std::make_unique<ScUndoInsertTab>( pDocSh, nTab, true, rName));
2454 GetViewData().InsertTab( nTab );
2455 SetTabNo( nTab, true );
2456 pDocSh->PostPaintExtras();
2457 pDocSh->SetDocumentModified();
2458 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2459 return true;
2460 }
2461 else
2462 {
2463 return false;
2464 }
2465}
2466
2467void ScViewFunc::DeleteTable( SCTAB nTab, bool bRecord )
2468{
2469 ScDocShell* pDocSh = GetViewData().GetDocShell();
2470 ScDocument& rDoc = pDocSh->GetDocument();
2471
2472 bool bSuccess = pDocSh->GetDocFunc().DeleteTable( nTab, bRecord );
2473 if (bSuccess)
2474 {
2475 SCTAB nNewTab = nTab;
2476 if ( nNewTab >= rDoc.GetTableCount() )
2477 --nNewTab;
2478 SetTabNo( nNewTab, true );
2479 }
2480}
2481
2482//only use this method for undo for now, all sheets must be connected
2483//this method doesn't support undo for now, merge it when it with the other method later
2484void ScViewFunc::DeleteTables( const SCTAB nTab, SCTAB nSheets )
2485{
2486 ScDocShell* pDocSh = GetViewData().GetDocShell();
2487 ScDocument& rDoc = pDocSh->GetDocument();
2488 bool bVbaEnabled = rDoc.IsInVBAMode();
2489 SCTAB nNewTab = nTab;
2490 weld::WaitObject aWait(GetViewData().GetDialogParent());
2491
2492 while ( nNewTab > 0 && !rDoc.IsVisible( nNewTab ) )
2493 --nNewTab;
2494
2495 if (!rDoc.DeleteTabs(nTab, nSheets))
2496 return;
2497
2498 if( bVbaEnabled )
2499 {
2500 for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
2501 {
2502 OUString sCodeName;
2503 bool bHasCodeName = rDoc.GetCodeName( nTab + aTab, sCodeName );
2504 if ( bHasCodeName )
2505 VBA_DeleteModule( *pDocSh, sCodeName );
2506 }
2507 }
2508
2509 pDocSh->Broadcast( ScTablesHint( SC_TABS_DELETED, nTab, nSheets ) );
2510 if ( nNewTab >= rDoc.GetTableCount() )
2511 nNewTab = rDoc.GetTableCount() - 1;
2512 SetTabNo( nNewTab, true );
2513
2514 pDocSh->PostPaintExtras();
2515 pDocSh->SetDocumentModified();
2516
2517 SfxApplication* pSfxApp = SfxGetpApp(); // Navigator
2518 pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2519 pSfxApp->Broadcast( SfxHint( SfxHintId::ScDbAreasChanged ) );
2520 pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) );
2521}
2522
2523bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, bool bRecord )
2524{
2525 ScDocShell* pDocSh = GetViewData().GetDocShell();
2526 ScDocument& rDoc = pDocSh->GetDocument();
2527 bool bVbaEnabled = rDoc.IsInVBAMode();
2528 SCTAB nNewTab = TheTabs.front();
2529 weld::WaitObject aWait(GetViewData().GetDialogParent());
2530 if (bRecord && !rDoc.IsUndoEnabled())
2531 bRecord = false;
2532 if ( bVbaEnabled )
2533 bRecord = false;
2534
2535 while ( nNewTab > 0 && !rDoc.IsVisible( nNewTab ) )
2536 --nNewTab;
2537
2538 bool bWasLinked = false;
2539 ScDocumentUniquePtr pUndoDoc;
2540 std::unique_ptr<ScRefUndoData> pUndoData;
2541 if (bRecord)
2542 {
2543 pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
2544 SCTAB nCount = rDoc.GetTableCount();
2545
2546 OUString aOldName;
2547 for(size_t i=0; i<TheTabs.size(); ++i)
2548 {
2549 SCTAB nTab = TheTabs[i];
2550 if (i==0)
2551 pUndoDoc->InitUndo( rDoc, nTab,nTab, true,true ); // incl. column/fow flags
2552 else
2553 pUndoDoc->AddUndoTab( nTab,nTab, true,true ); // incl. column/fow flags
2554
2555 rDoc.CopyToDocument(0,0,nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab, InsertDeleteFlags::ALL,false, *pUndoDoc );
2556 rDoc.GetName( nTab, aOldName );
2557 pUndoDoc->RenameTab( nTab, aOldName );
2558 if (rDoc.IsLinked(nTab))
2559 {
2560 bWasLinked = true;
2561 pUndoDoc->SetLink( nTab, rDoc.GetLinkMode(nTab), rDoc.GetLinkDoc(nTab),
2562 rDoc.GetLinkFlt(nTab), rDoc.GetLinkOpt(nTab),
2563 rDoc.GetLinkTab(nTab),
2564 rDoc.GetLinkRefreshDelay(nTab) );
2565 }
2566 if ( rDoc.IsScenario(nTab) )
2567 {
2568 pUndoDoc->SetScenario( nTab, true );
2569 OUString aComment;
2570 Color aColor;
2571 ScScenarioFlags nScenFlags;
2572 rDoc.GetScenarioData( nTab, aComment, aColor, nScenFlags );
2573 pUndoDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
2574 bool bActive = rDoc.IsActiveScenario( nTab );
2575 pUndoDoc->SetActiveScenario( nTab, bActive );
2576 }
2577 pUndoDoc->SetVisible( nTab, rDoc.IsVisible( nTab ) );
2578 pUndoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) );
2579 auto pSheetEvents = rDoc.GetSheetEvents( nTab );
2580 pUndoDoc->SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) );
2581 pUndoDoc->SetLayoutRTL( nTab, rDoc.IsLayoutRTL( nTab ) );
2582
2583 if ( rDoc.IsTabProtected( nTab ) )
2584 pUndoDoc->SetTabProtection(nTab, rDoc.GetTabProtection(nTab));
2585
2586 // Drawing-Layer is responsible for its Undo !!!
2587 // pUndoDoc->TransferDrawPage(rDoc, nTab,nTab);
2588 }
2589
2590 pUndoDoc->AddUndoTab( 0, nCount-1 ); // all Tabs for references
2591
2592 rDoc.BeginDrawUndo(); // DeleteTab creates a SdrUndoDelPage
2593
2594 pUndoData.reset(new ScRefUndoData( &rDoc ));
2595 }
2596
2597 bool bDelDone = false;
2598
2599 for(int i=TheTabs.size()-1; i>=0; --i)
2600 {
2601 OUString sCodeName;
2602 bool bHasCodeName = rDoc.GetCodeName( TheTabs[i], sCodeName );
2603 if (rDoc.DeleteTab(TheTabs[i]))
2604 {
2605 bDelDone = true;
2606 if( bVbaEnabled && bHasCodeName )
2607 {
2608 VBA_DeleteModule( *pDocSh, sCodeName );
2609 }
2610 pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[i] ) );
2611 }
2612 }
2613 if (bRecord)
2614 {
2615 pDocSh->GetUndoManager()->AddUndoAction(
2616 std::make_unique<ScUndoDeleteTab>( GetViewData().GetDocShell(), TheTabs,
2617 std::move(pUndoDoc), std::move(pUndoData) ));
2618 }
2619
2620 if (bDelDone)
2621 {
2622 if ( nNewTab >= rDoc.GetTableCount() )
2623 nNewTab = rDoc.GetTableCount() - 1;
2624
2625 SetTabNo( nNewTab, true );
2626
2627 if (bWasLinked)
2628 {
2629 pDocSh->UpdateLinks(); // update Link-Manager
2630 GetViewData().GetBindings().Invalidate(SID_LINKS);
2631 }
2632
2633 pDocSh->PostPaintExtras();
2634 pDocSh->SetDocumentModified();
2635
2636 SfxApplication* pSfxApp = SfxGetpApp(); // Navigator
2637 pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2638 pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
2639 pSfxApp->Broadcast( SfxHint( SfxHintId::ScDbAreasChanged ) );
2640 pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) );
2641 }
2642 return bDelDone;
2643}
2644
2645bool ScViewFunc::RenameTable( const OUString& rName, SCTAB nTab )
2646{
2647 // order Table/Name is inverted for DocFunc
2648 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().
2649 RenameTable( nTab, rName, true, false );
2650 if (bSuccess)
2651 {
2652 // the table name might be part of a formula
2654 }
2655 return bSuccess;
2656}
2657
2658bool ScViewFunc::SetTabBgColor( const Color& rColor, SCTAB nTab )
2659{
2660 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().SetTabBgColor( nTab, rColor, true, false );
2661 if (bSuccess)
2662 {
2664 }
2665 return bSuccess;
2666}
2667
2668bool ScViewFunc::SetTabBgColor( ScUndoTabColorInfo::List& rUndoSetTabBgColorInfoList )
2669{
2670 bool bSuccess = GetViewData().GetDocShell()->GetDocFunc().SetTabBgColor( rUndoSetTabBgColorInfoList, false );
2671 if (bSuccess)
2672 {
2674 }
2675 return bSuccess;
2676}
2677
2678void ScViewFunc::InsertAreaLink( const OUString& rFile,
2679 const OUString& rFilter, const OUString& rOptions,
2680 const OUString& rSource )
2681{
2682 ScDocShell* pDocSh = GetViewData().GetDocShell();
2683 SCCOL nPosX = GetViewData().GetCurX();
2684 SCROW nPosY = GetViewData().GetCurY();
2685 SCTAB nTab = GetViewData().GetTabNo();
2686 ScAddress aPos( nPosX, nPosY, nTab );
2687
2688 pDocSh->GetDocFunc().InsertAreaLink( rFile, rFilter, rOptions, rSource, aPos, 0/*nRefresh*/, false, false );
2689}
2690
2691void ScViewFunc::InsertTableLink( const OUString& rFile,
2692 const OUString& rFilter, const OUString& rOptions,
2693 std::u16string_view rTabName )
2694{
2695 OUString aFilterName = rFilter;
2696 OUString aOpt = rOptions;
2697 ScDocumentLoader aLoader( rFile, aFilterName, aOpt );
2698 if (aLoader.IsError())
2699 return;
2700
2701 ScDocShell* pSrcSh = aLoader.GetDocShell();
2702 ScDocument& rSrcDoc = pSrcSh->GetDocument();
2703 SCTAB nTab = MAXTAB+1;
2704 if (rTabName.empty()) // no name given -> first table
2705 nTab = 0;
2706 else
2707 {
2708 OUString aTemp;
2709 SCTAB nCount = rSrcDoc.GetTableCount();
2710 for (SCTAB i=0; i<nCount; i++)
2711 {
2712 rSrcDoc.GetName( i, aTemp );
2713 if ( aTemp == rTabName )
2714 nTab = i;
2715 }
2716 }
2717
2718 if ( nTab <= MAXTAB )
2719 ImportTables( pSrcSh, 1, &nTab, true,
2720 GetViewData().GetTabNo() );
2721}
2722
2723// Copy/link tables from another document
2724
2726 SCTAB nCount, const SCTAB* pSrcTabs, bool bLink,SCTAB nTab )
2727{
2728 ScDocument& rSrcDoc = pSrcShell->GetDocument();
2729
2730 ScDocShell* pDocSh = GetViewData().GetDocShell();
2731 ScDocument& rDoc = pDocSh->GetDocument();
2732 bool bUndo(rDoc.IsUndoEnabled());
2733
2734 bool bError = false;
2735 bool bRefs = false;
2736 bool bName = false;
2737
2738 if (rSrcDoc.GetDrawLayer())
2739 pDocSh->MakeDrawLayer();
2740
2741 if (bUndo)
2742 rDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
2743
2744 SCTAB nInsCount = 0;
2745 SCTAB i;
2746 for( i=0; i<nCount; i++ )
2747 { // insert sheets first and update all references
2748 OUString aName;
2749 rSrcDoc.GetName( pSrcTabs[i], aName );
2750 rDoc.CreateValidTabName( aName );
2751 if ( !rDoc.InsertTab( nTab+i, aName ) )
2752 {
2753 bError = true; // total error
2754 break; // for
2755 }
2756 ++nInsCount;
2757 }
2758 for (i=0; i<nCount && !bError; i++)
2759 {
2760 SCTAB nSrcTab = pSrcTabs[i];
2761 SCTAB nDestTab1=nTab+i;
2762 sal_uLong nErrVal = pDocSh->TransferTab( *pSrcShell, nSrcTab, nDestTab1,
2763 false, false ); // no insert
2764
2765 switch (nErrVal)
2766 {
2767 case 0: // internal error or full of errors
2768 bError = true;
2769 break;
2770 case 2:
2771 bRefs = true;
2772 break;
2773 case 3:
2774 bName = true;
2775 break;
2776 case 4:
2777 bRefs = bName = true;
2778 break;
2779 }
2780
2781 }
2782
2783 if (bLink)
2784 {
2785 sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
2786
2787 SfxMedium* pMed = pSrcShell->GetMedium();
2788 OUString aFileName = pMed->GetName();
2789 OUString aFilterName;
2790 if (pMed->GetFilter())
2791 aFilterName = pMed->GetFilter()->GetFilterName();
2792 OUString aOptions = ScDocumentLoader::GetOptions(*pMed);
2793
2794 bool bWasThere = rDoc.HasLink( aFileName, aFilterName, aOptions );
2795
2796 sal_uLong nRefresh = 0;
2797 OUString aTabStr;
2798 for (i=0; i<nInsCount; i++)
2799 {
2800 rSrcDoc.GetName( pSrcTabs[i], aTabStr );
2801 rDoc.SetLink( nTab+i, ScLinkMode::NORMAL,
2802 aFileName, aFilterName, aOptions, aTabStr, nRefresh );
2803 }
2804
2805 if (!bWasThere) // Insert link only once per source document
2806 {
2807 ScTableLink* pLink = new ScTableLink( pDocSh, aFileName, aFilterName, aOptions, nRefresh );
2808 pLink->SetInCreate( true );
2809 pLinkManager->InsertFileLink( *pLink, sfx2::SvBaseLinkObjectType::ClientFile, aFileName, &aFilterName );
2810 pLink->Update();
2811 pLink->SetInCreate( false );
2812
2813 SfxBindings& rBindings = GetViewData().GetBindings();
2814 rBindings.Invalidate( SID_LINKS );
2815 }
2816 }
2817
2818 if (bUndo)
2819 {
2820 pDocSh->GetUndoManager()->AddUndoAction(
2821 std::make_unique<ScUndoImportTab>( pDocSh, nTab, nCount ) );
2822 }
2823
2824 for (i=0; i<nInsCount; i++)
2825 GetViewData().InsertTab(nTab);
2826 SetTabNo(nTab,true);
2827 pDocSh->PostPaint( 0,0,0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB,
2829
2830 SfxApplication* pSfxApp = SfxGetpApp();
2831 pSfxApp->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
2832 pSfxApp->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
2833
2834 pDocSh->PostPaintExtras();
2835 pDocSh->PostPaintGridAll();
2836 pDocSh->SetDocumentModified();
2837
2838 if (bRefs)
2839 ErrorMessage(STR_ABSREFLOST);
2840 if (bName)
2841 ErrorMessage(STR_NAMECONFLICT);
2842}
2843
2844// Move/Copy table to another document
2845
2847 sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString* pNewTabName )
2848{
2850 ScDocShell* pDocShell = GetViewData().GetDocShell();
2851 ScDocShell* pDestShell = nullptr;
2852 ScTabViewShell* pDestViewSh = nullptr;
2853 bool bUndo (rDoc.IsUndoEnabled());
2854 bool bRename = pNewTabName && !pNewTabName->isEmpty();
2855
2856 bool bNewDoc = (nDestDocNo == SC_DOC_NEW);
2857 if ( bNewDoc )
2858 {
2859 nDestTab = 0; // firstly insert
2860
2861 // execute without SfxCallMode::RECORD, because already contained in move command
2862
2863 SfxStringItem aItem( SID_FILE_NAME, "private:factory/" + STRING_SCAPP );
2864 SfxStringItem aTarget( SID_TARGETNAME, "_blank" );
2865
2866 const SfxPoolItem* pRetItem = GetViewData().GetDispatcher().ExecuteList(
2867 SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON,
2868 { &aItem, &aTarget });
2869 if ( pRetItem )
2870 {
2871 if ( auto pObjectItem = dynamic_cast<const SfxObjectItem*>(pRetItem) )
2872 pDestShell = dynamic_cast<ScDocShell*>( pObjectItem->GetShell() );
2873 else if ( auto pViewFrameItem = dynamic_cast<const SfxViewFrameItem*>( pRetItem) )
2874 {
2875 SfxViewFrame* pFrm = pViewFrameItem->GetFrame();
2876 if (pFrm)
2877 pDestShell = dynamic_cast<ScDocShell*>( pFrm->GetObjectShell() );
2878 }
2879 if (pDestShell)
2880 pDestViewSh = pDestShell->GetBestViewShell();
2881 }
2882 }
2883 else
2884 pDestShell = ScDocShell::GetShellByNum( nDestDocNo );
2885
2886 if (!pDestShell)
2887 {
2888 OSL_FAIL("Destination document not found !!!");
2889 return;
2890 }
2891
2892 ScMarkData& rMark = GetViewData().GetMarkData();
2893 if (bRename && rMark.GetSelectCount() != 1)
2894 {
2895 // Custom sheet name is provided, but more than one sheet is selected.
2896 // We don't support this scenario at the moment.
2897 return;
2898 }
2899
2900 ScDocument& rDestDoc = pDestShell->GetDocument();
2901
2902 if (&rDestDoc != &rDoc)
2903 {
2904 if (bNewDoc)
2905 {
2906 while (rDestDoc.GetTableCount() > 1)
2907 rDestDoc.DeleteTab(0);
2908 rDestDoc.RenameTab( 0, "______42_____" );
2909 }
2910
2911 SCTAB nTabCount = rDoc.GetTableCount();
2912 SCTAB nTabSelCount = rMark.GetSelectCount();
2913
2914 vector<SCTAB> TheTabs;
2915
2916 for(SCTAB i=0; i<nTabCount; ++i)
2917 {
2918 if(rMark.GetTableSelect(i))
2919 {
2920 OUString aTabName;
2921 rDoc.GetName( i, aTabName);
2922 TheTabs.push_back(i);
2923 for(SCTAB j=i+1;j<nTabCount;j++)
2924 {
2925 if((!rDoc.IsVisible(j)) && rDoc.IsScenario(j))
2926 {
2927 rDoc.GetName( j, aTabName);
2928 TheTabs.push_back(j);
2929 i=j;
2930 }
2931 else break;
2932 }
2933 }
2934 }
2935
2937
2938 if (rDoc.GetDrawLayer())
2939 pDestShell->MakeDrawLayer();
2940
2941 if (!bNewDoc && bUndo)
2942 rDestDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
2943
2944 sal_uLong nErrVal =1;
2945 if(nDestTab==SC_TAB_APPEND)
2946 nDestTab=rDestDoc.GetTableCount();
2947 SCTAB nDestTab1=nDestTab;
2948 ScClipParam aParam;
2949 for( size_t j=0; j<TheTabs.size(); ++j, ++nDestTab1 )
2950 { // insert sheets first and update all references
2951 OUString aName;
2952 if (bRename)
2953 aName = *pNewTabName;
2954 else
2955 rDoc.GetName( TheTabs[j], aName );
2956
2957 rDestDoc.CreateValidTabName( aName );
2958 if ( !rDestDoc.InsertTab( nDestTab1, aName ) )
2959 {
2960 nErrVal = 0; // total error
2961 break; // for
2962 }
2963 ScRange aRange( 0, 0, TheTabs[j], rDoc.MaxCol(), rDoc.MaxRow(), TheTabs[j] );
2964 aParam.maRanges.push_back(aRange);
2965 }
2966 rDoc.SetClipParam(aParam);
2967 if ( nErrVal > 0 )
2968 {
2969 nDestTab1 = nDestTab;
2970 for(SCTAB nTab : TheTabs)
2971 {
2972 nErrVal = pDestShell->TransferTab( *pDocShell, nTab, nDestTab1, false, false );
2973 nDestTab1++;
2974 }
2975 }
2976 if (!bNewDoc && bUndo)
2977 {
2978 OUString sName;
2979 rDestDoc.GetName(nDestTab, sName);
2980 pDestShell->GetUndoManager()->AddUndoAction(
2981 std::make_unique<ScUndoImportTab>( pDestShell, nDestTab,
2982 static_cast<SCTAB>(TheTabs.size())));
2983
2984 }
2985 else
2986 {
2987 pDestShell->GetUndoManager()->Clear();
2988 }
2989
2991 switch (nErrVal)
2992 {
2993 case 0: // internal error or full of errors
2994 {
2995 ErrorMessage(STR_TABINSERT_ERROR);
2996 return;
2997 }
2998 case 2:
2999 ErrorMessage(STR_ABSREFLOST);
3000 break;
3001 case 3:
3002 ErrorMessage(STR_NAMECONFLICT);
3003 break;
3004 case 4:
3005 {
3006 ErrorMessage(STR_ABSREFLOST);
3007 ErrorMessage(STR_NAMECONFLICT);
3008 }
3009 break;
3010 default:
3011 break;
3012 }
3013
3014 if (!bCopy)
3015 {
3016 if(nTabCount!=nTabSelCount)
3017 DeleteTables(TheTabs); // incl. Paint & Undo
3018 else
3019 ErrorMessage(STR_TABREMOVE_ERROR);
3020 }
3021
3022 if (bNewDoc)
3023 {
3024 // ChartListenerCollection must be updated before DeleteTab
3025 if ( rDestDoc.IsChartListenerCollectionNeedsUpdate() )
3027
3028 SCTAB nNumTabsInserted = static_cast<SCTAB>(TheTabs.size());
3029 pDestShell->Broadcast( ScTablesHint( SC_TABS_INSERTED, 0, nNumTabsInserted ) );
3030
3031 rDestDoc.DeleteTab( nNumTabsInserted ); // old first table
3032 pDestShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nNumTabsInserted ) );
3033
3034 if (pDestViewSh)
3035 {
3036 // Make sure to clear the cached page view after sheet
3037 // deletion, which still points to the sdr page belonging to
3038 // the deleted sheet.
3039 SdrView* pSdrView = pDestViewSh->GetScDrawView();
3040 if (pSdrView)
3041 pSdrView->ClearPageView();
3042
3043 pDestViewSh->TabChanged(); // pages on the drawing layer
3044 }
3045 pDestShell->PostPaint( 0,0,0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB,
3048 // PaintPartFlags::Size for outline
3049 }
3050 else
3051 {
3052 pDestShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, nDestTab ) );
3053 pDestShell->PostPaintExtras();
3054 pDestShell->PostPaintGridAll();
3055 }
3056
3057 TheTabs.clear();
3058
3059 pDestShell->SetDocumentModified();
3060 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3061 }
3062 else
3063 {
3064 // Move or copy within the same document.
3065 SCTAB nTabCount = rDoc.GetTableCount();
3066
3067 unique_ptr< vector<SCTAB> > pSrcTabs(new vector<SCTAB>);
3068 unique_ptr< vector<SCTAB> > pDestTabs(new vector<SCTAB>);
3069 unique_ptr< vector<OUString> > pTabNames(new vector<OUString>);
3070 unique_ptr< vector<OUString> > pDestNames;
3071 pSrcTabs->reserve(nTabCount);
3072 pDestTabs->reserve(nTabCount);
3073 pTabNames->reserve(nTabCount);
3074 OUString aDestName;
3075
3076 for(SCTAB i=0;i<nTabCount;i++)
3077 {
3078 if(rMark.GetTableSelect(i))
3079 {
3080 OUString aTabName;
3081 rDoc.GetName( i, aTabName);
3082 pTabNames->push_back(aTabName);
3083
3084 for(SCTAB j=i+1;j<nTabCount;j++)
3085 {
3086 if((!rDoc.IsVisible(j)) && rDoc.IsScenario(j))
3087 {
3088 rDoc.GetName( j, aTabName);
3089 pTabNames->push_back(aTabName);
3090 i=j;
3091 }
3092 else break;
3093 }
3094 }
3095 }
3096
3097 if (bCopy && bUndo)
3098 rDoc.BeginDrawUndo(); // drawing layer must do its own undo actions
3099
3100 rDoc.GetName( nDestTab, aDestName);
3101 SCTAB nDestTab1=nDestTab;
3102 SCTAB nMovTab=0;
3103 for (size_t j = 0, n = pTabNames->size(); j < n; ++j)
3104 {
3105 nTabCount = rDoc.GetTableCount();
3106 const OUString& rStr = (*pTabNames)[j];
3107 if(!rDoc.GetTable(rStr,nMovTab))
3108 {
3109 nMovTab=nTabCount;
3110 }
3111 if(!rDoc.GetTable(aDestName,nDestTab1))
3112 {
3113 nDestTab1=nTabCount;
3114 }
3115 pDocShell->MoveTable( nMovTab, nDestTab1, bCopy, false ); // Undo is here
3116
3117 // tdf#43175 - Adjust chart references on every copied sheet
3118 if (bCopy)
3119 {
3120 // New position of source table after moving
3121 SCTAB nSrcTab = (nDestTab1 <= nMovTab) ? nMovTab + 1 : nMovTab;
3122 //#i29848# adjust references to data on the copied sheet
3124 nDestTab1);
3125 }
3126
3127 if(bCopy && rDoc.IsScenario(nMovTab))
3128 {
3129 OUString aComment;
3130 Color aColor;
3131 ScScenarioFlags nFlags;
3132
3133 rDoc.GetScenarioData(nMovTab, aComment,aColor, nFlags);
3134 rDoc.SetScenario(nDestTab1,true);
3135 rDoc.SetScenarioData(nDestTab1,aComment,aColor,nFlags);
3136 bool bActive = rDoc.IsActiveScenario(nMovTab );
3137 rDoc.SetActiveScenario( nDestTab1, bActive );
3138 bool bVisible=rDoc.IsVisible(nMovTab);
3139 rDoc.SetVisible(nDestTab1,bVisible );
3140 }
3141
3142 pSrcTabs->push_back(nMovTab);
3143
3144 if(!bCopy)
3145 {
3146 if(!rDoc.GetTable(rStr,nDestTab1))
3147 {
3148 nDestTab1=nTabCount;
3149 }
3150 }
3151
3152 pDestTabs->push_back(nDestTab1);
3153 }
3154
3155 // Rename must be done after all sheets have been moved.
3156 if (bRename)
3157 {
3158 pDestNames.reset(new vector<OUString>);
3159 size_t n = pDestTabs->size();
3160 pDestNames->reserve(n);
3161 for (size_t j = 0; j < n; ++j)
3162 {
3163 SCTAB nRenameTab = (*pDestTabs)[j];
3164 OUString aTabName = *pNewTabName;
3165 rDoc.CreateValidTabName( aTabName );
3166 pDestNames->push_back(aTabName);
3167 rDoc.RenameTab(nRenameTab, aTabName);
3168 }
3169 }
3170 else
3171 // No need to keep this around when we are not renaming.
3172 pTabNames.reset();
3173
3174 SCTAB nTab = GetViewData().GetTabNo();
3175
3176 if (bUndo)
3177 {
3178 if (bCopy)
3179 {
3180 pDocShell->GetUndoManager()->AddUndoAction(
3181 std::make_unique<ScUndoCopyTab>(
3182 pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pDestNames)));
3183 }
3184 else
3185 {
3186 pDocShell->GetUndoManager()->AddUndoAction(
3187 std::make_unique<ScUndoMoveTab>(
3188 pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pTabNames), std::move(pDestNames)));
3189 }
3190 }
3191
3192 SCTAB nNewTab = nDestTab;
3193 if (nNewTab == SC_TAB_APPEND)
3194 nNewTab = rDoc.GetTableCount()-1;
3195 else if (!bCopy && nTab<nDestTab)
3196 nNewTab--;
3197
3198 SetTabNo( nNewTab, true );
3199 }
3200}
3201
3202void ScViewFunc::ShowTable( const std::vector<OUString>& rNames )
3203{
3204 ScDocShell* pDocSh = GetViewData().GetDocShell();
3205 ScDocument& rDoc = pDocSh->GetDocument();
3206 bool bUndo(rDoc.IsUndoEnabled());
3207
3208 std::vector<SCTAB> undoTabs;
3209 SCTAB nPos = 0;
3210
3211 bool bFound(false);
3212
3213 for (const OUString& aName : rNames)
3214 {
3215 if (rDoc.GetTable(aName, nPos))
3216 {
3217 rDoc.SetVisible( nPos, true );
3218 SetTabNo( nPos, true );
3219 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3220 if (!bFound)
3221 bFound = true;
3222 if (bUndo)
3223 undoTabs.push_back(nPos);
3224 }
3225 }
3226 if (bFound)
3227 {
3228 if (bUndo)
3229 {
3230 pDocSh->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoShowHideTab>( pDocSh, std::move(undoTabs), true ) );
3231 }
3232 pDocSh->PostPaint(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB, PaintPartFlags::Extras);
3233 pDocSh->SetDocumentModified();
3234 }
3235}
3236
3237void ScViewFunc::HideTable( const ScMarkData& rMark, SCTAB nTabToSelect )
3238{
3239 ScDocShell* pDocSh = GetViewData().GetDocShell();
3240 ScDocument& rDoc = pDocSh->GetDocument();
3241 bool bUndo(rDoc.IsUndoEnabled());
3242 SCTAB nVisible = 0;
3243 SCTAB nTabCount = rDoc.GetTableCount();
3244
3245 SCTAB nTabSelCount = rMark.GetSelectCount();
3246
3247 // check to make sure we won't hide all sheets. we need at least one visible at all times.
3248 for ( SCTAB i=0; i < nTabCount && nVisible <= nTabSelCount ; i++ )
3249 if (rDoc.IsVisible(i))
3250 ++nVisible;
3251
3252 if (nVisible <= nTabSelCount)
3253 return;
3254
3255 std::vector<SCTAB> undoTabs;
3256
3257 // need to take a copy of selectedtabs since it is modified in the loop
3258 const ScMarkData::MarkedTabsType selectedTabs = rMark.GetSelectedTabs();
3259 for (const SCTAB& nTab : selectedTabs)
3260 {
3261 if (rDoc.IsVisible( nTab ))
3262 {
3263 rDoc.SetVisible( nTab, false );
3264 // Update views
3265 pDocSh->Broadcast( ScTablesHint( SC_TAB_HIDDEN, nTab ) );
3266 SetTabNo( nTab, true );
3267 // Store for undo
3268 if (bUndo)
3269 undoTabs.push_back(nTab);
3270 }
3271 }
3272
3273 if (nTabToSelect != -1)
3274 SetTabNo(nTabToSelect);
3275
3276 if (bUndo)
3277 {
3278 pDocSh->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoShowHideTab>( pDocSh, std::move(undoTabs), false ) );
3279 }
3280
3281 // Update views
3282 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );
3283 pDocSh->PostPaint(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB, PaintPartFlags::Extras);
3284 pDocSh->SetDocumentModified();
3285}
3286
3287void ScViewFunc::InsertSpecialChar( const OUString& rStr, const vcl::Font& rFont )
3288{
3289 ScEditableTester aTester( this );
3290 if (!aTester.IsEditable())
3291 {
3292 ErrorMessage(aTester.GetMessageId());
3293 return;
3294 }
3295
3296 const sal_Unicode* pChar = rStr.getStr();
3297 ScTabViewShell* pViewShell = GetViewData().GetViewShell();
3298 SvxFontItem aFontItem( rFont.GetFamilyType(),
3299 rFont.GetFamilyName(),
3300 rFont.GetStyleName(),
3301 rFont.GetPitch(),
3302 rFont.GetCharSet(),
3303 ATTR_FONT );
3304
3305 // if string contains WEAK characters, set all fonts
3306 SvtScriptType nScript;
3308 if ( rDoc.HasStringWeakCharacters( rStr ) )
3309 nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
3310 else
3311 nScript = rDoc.GetStringScriptType( rStr );
3312
3313 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, pViewShell->GetPool() );
3314 aSetItem.PutItemForScriptType( nScript, aFontItem );
3315 ApplyUserItemSet( aSetItem.GetItemSet() );
3316
3317 while ( *pChar )
3318 pViewShell->TabKeyInput( KeyEvent( *(pChar++), vcl::KeyCode() ) );
3319}
3320
3321void ScViewFunc::UpdateLineAttrs( SvxBorderLine& rLine,
3322 const SvxBorderLine* pDestLine,
3323 const SvxBorderLine* pSrcLine,
3324 bool bColor )
3325{
3326 if ( !(pSrcLine && pDestLine) )
3327 return;
3328
3329 if ( bColor )
3330 {
3331 rLine.SetColor ( pSrcLine->GetColor() );
3332 rLine.SetBorderLineStyle(pDestLine->GetBorderLineStyle());
3333 rLine.SetWidth ( pDestLine->GetWidth() );
3334 }
3335 else
3336 {
3337 rLine.SetColor ( pDestLine->GetColor() );
3338 rLine.SetBorderLineStyle(pSrcLine->GetBorderLineStyle());
3339 rLine.SetWidth ( pSrcLine->GetWidth() );
3340 }
3341}
3342
3343#define SET_LINE_ATTRIBUTES(LINE,BOXLINE) \
3344 pBoxLine = aBoxItem.Get##LINE(); \
3345 if ( pBoxLine ) \
3346 { \
3347 if ( pLine ) \
3348 { \
3349 UpdateLineAttrs( aLine, pBoxLine, pLine, bColorOnly ); \
3350 aBoxItem.SetLine( &aLine, BOXLINE ); \
3351 } \
3352 else \
3353 aBoxItem.SetLine( nullptr, BOXLINE ); \
3354 }
3355
3356void ScViewFunc::SetSelectionFrameLines( const SvxBorderLine* pLine,
3357 bool bColorOnly )
3358{
3359 // Not editable only due to a matrix? Attribute is ok anyhow.
3360 bool bOnlyNotBecauseOfMatrix;
3361 if ( !SelectionEditable( &bOnlyNotBecauseOfMatrix ) && !bOnlyNotBecauseOfMatrix )
3362 {
3363 ErrorMessage(STR_PROTECTIONERR);
3364 return;
3365 }
3366
3368 ScMarkData aFuncMark( GetViewData().GetMarkData() ); // local copy for UnmarkFiltered
3369 ScViewUtil::UnmarkFiltered( aFuncMark, rDoc );
3370 ScDocShell* pDocSh = GetViewData().GetDocShell();
3371 const ScPatternAttr* pSelAttrs = GetSelectionPattern();
3372 const SfxItemSet& rSelItemSet = pSelAttrs->GetItemSet();
3373
3374 const SfxPoolItem* pBorderAttr = nullptr;
3375 SfxItemState eItemState = rSelItemSet.GetItemState( ATTR_BORDER, true, &pBorderAttr );
3376
3377 const SfxPoolItem* pTLBRItem = nullptr;
3378 SfxItemState eTLBRState = rSelItemSet.GetItemState( ATTR_BORDER_TLBR, true, &pTLBRItem );
3379
3380 const SfxPoolItem* pBLTRItem = nullptr;
3381 SfxItemState eBLTRState = rSelItemSet.GetItemState( ATTR_BORDER_BLTR, true, &pBLTRItem );
3382
3383 // any of the lines visible?
3384 if( !((eItemState != SfxItemState::DEFAULT) || (eTLBRState != SfxItemState::DEFAULT) || (eBLTRState != SfxItemState::DEFAULT)) )
3385 return;
3386
3387 // none of the lines don't care?
3388 if( (eItemState != SfxItemState::DONTCARE) && (eTLBRState != SfxItemState::DONTCARE) && (eBLTRState != SfxItemState::DONTCARE) )
3389 {
3392
3393 SvxBorderLine aLine;
3394
3395 if( pBorderAttr )
3396 {
3397 const SvxBorderLine* pBoxLine = nullptr;
3398 SvxBoxItem aBoxItem( *static_cast<const SvxBoxItem*>(pBorderAttr) );
3399 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
3400
3401 // here pBoxLine is used
3402 SET_LINE_ATTRIBUTES(Top,SvxBoxItemLine::TOP)
3403 SET_LINE_ATTRIBUTES(Bottom,SvxBoxItemLine::BOTTOM)
3404 SET_LINE_ATTRIBUTES(Left,SvxBoxItemLine::LEFT)
3405 SET_LINE_ATTRIBUTES(Right,SvxBoxItemLine::RIGHT)
3406
3407 aBoxInfoItem.SetLine( aBoxItem.GetTop(), SvxBoxInfoItemLine::HORI );
3408 aBoxInfoItem.SetLine( aBoxItem.GetLeft(), SvxBoxInfoItemLine::VERT );
3409 aBoxInfoItem.ResetFlags(); // set Lines to Valid
3410
3411 aOldSet.Put( *pBorderAttr );
3412 aNewSet.Put( aBoxItem );
3413 aNewSet.Put( aBoxInfoItem );
3414 }
3415
3416 if( pTLBRItem && static_cast<const SvxLineItem*>(pTLBRItem)->GetLine() )
3417 {
3418 SvxLineItem aTLBRItem( *static_cast<const SvxLineItem*>(pTLBRItem) );
3419 UpdateLineAttrs( aLine, aTLBRItem.GetLine(), pLine, bColorOnly );
3420 aTLBRItem.SetLine( &aLine );
3421 aOldSet.Put( *pTLBRItem );
3422 aNewSet.Put( aTLBRItem );
3423 }
3424
3425 if( pBLTRItem && static_cast<const SvxLineItem*>(pBLTRItem)->GetLine() )
3426 {
3427 SvxLineItem aBLTRItem( *static_cast<const SvxLineItem*>(pBLTRItem) );
3428 UpdateLineAttrs( aLine, aBLTRItem.GetLine(), pLine, bColorOnly );
3429 aBLTRItem.SetLine( &aLine );
3430 aOldSet.Put( *pBLTRItem );
3431 aNewSet.Put( aBLTRItem );
3432 }
3433
3434 ApplyAttributes( &aNewSet, &aOldSet );
3435 }
3436 else // if ( eItemState == SfxItemState::DONTCARE )
3437 {
3438 aFuncMark.MarkToMulti();
3439 rDoc.ApplySelectionLineStyle( aFuncMark, pLine, bColorOnly );
3440 }
3441
3442 const ScRange& aMarkRange = aFuncMark.GetMultiMarkArea();
3443 SCCOL nStartCol = aMarkRange.aStart.Col();
3444 SCROW nStartRow = aMarkRange.aStart.Row();
3445 SCTAB nStartTab = aMarkRange.aStart.Tab();
3446 SCCOL nEndCol = aMarkRange.aEnd.Col();
3447 SCROW nEndRow = aMarkRange.aEnd.Row();
3448 SCTAB nEndTab = aMarkRange.aEnd.Tab();
3449 pDocSh->PostPaint( nStartCol, nStartRow, nStartTab,
3450 nEndCol, nEndRow, nEndTab,
3452
3453 pDocSh->UpdateOle(GetViewData());
3454 pDocSh->SetDocumentModified();
3455}
3456
3457#undef SET_LINE_ATTRIBUTES
3458
3460{
3462 sal_uInt32 nIndex = rDoc.AddValidationEntry(rNew); // for it there is no Undo
3464
3465 ApplyAttr( aItem ); // with Paint and Undo...
3466}
3467
3468/* 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, const ILibreOfficeKitNotifier *pNotifier=nullptr)
sal_uInt32 GetValue() const
OUString GetText(LineEnd eEnd=LINEEND_LF) const
constexpr tools::Long Y() const
constexpr tools::Long X() 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:2465
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:4205
bool UnmergeCells(const ScRange &rRange, bool bRecord, ScUndoRemoveMerge *pUndoRemoveMerge)
Definition: docfunc.cxx:5050
bool SetTabBgColor(SCTAB nTab, const Color &rColor, bool bRecord, bool bApi)
Definition: docfunc.cxx:3534
bool TabOp(const ScRange &rRange, const ScMarkData *pTabMark, const ScTabOpParam &rParam, bool bRecord, bool bApi)
Definition: docfunc.cxx:4405
SC_DLLPUBLIC bool MergeCells(const ScCellMergeOption &rOption, bool bContents, bool bRecord, bool bApi, bool bEmptyMergedCells=false)
Definition: docfunc.cxx:4933
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:5514
void ConvertFormulaToValue(const ScRange &rRange, bool bInteraction)
Definition: docfunc.cxx:5727
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:4545
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:793
bool AdjustPrintZoom(const ScRange &rRange)
Definition: docsh4.cxx:1699
void PostPaintGridAll()
Definition: docsh3.cxx:183
void SetDocumentModified()
Definition: docsh.cxx:2982
void UseScenario(SCTAB nTab, const OUString &rName, bool bRecord=true)
Definition: docsh5.cxx:669
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
void PostDataChanged()
Definition: docsh3.cxx:93
ScDrawLayer * MakeDrawLayer()
Definition: docsh2.cxx:169
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
Definition: docsh4.cxx:2623
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:910
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: docsh3.cxx:451
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2653
sal_uLong TransferTab(ScDocShell &rSrcDocShell, SCTAB nSrcPos, SCTAB nDestPos, bool bInsertNew, bool bNotifyAndPaint)
Definition: docsh5.cxx:863
void SetPrintZoom(SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages)
Definition: docsh4.cxx:1666
ScModelObj * GetModel() const
Definition: docsh.hxx:432
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2968
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:221
void UpdateLinks() override
Definition: docsh6.cxx:318
static OUString GetOptions(const SfxMedium &rMedium)
Definition: tablink.cxx:423
bool IsError() const
Definition: tablink.cxx:577
ScDocShell * GetDocShell()
Definition: tablink.hxx:90
SC_DLLPUBLIC bool InsertTab(SCTAB nPos, const OUString &rName, bool bExternalDocument=false, bool bUndoDeleteTab=false)
Definition: document.cxx:485
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:478
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:898
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4161
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:43
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:420
SC_DLLPUBLIC OUString GetLinkTab(SCTAB nTab) const
Definition: documen3.cxx:530
SC_DLLPUBLIC const ScTableProtection * GetTabProtection(SCTAB nTab) const
Definition: documen3.cxx:1914
void UpdatePageBreaks(SCTAB nTab, const ScRange *pUserArea=nullptr)
Definition: document.cxx:6210
SC_DLLPUBLIC bool ExtendMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, SCTAB nTab, bool bRefresh=false)
Definition: document.cxx:5556
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:571
SC_DLLPUBLIC bool InsertTabs(SCTAB nPos, const std::vector< OUString > &rNames, bool bNamesValid=false)
Definition: document.cxx:573
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:449
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
Definition: document.cxx:244
bool HasStringWeakCharacters(const OUString &rString)
Definition: documen6.cxx:51
void BeginDrawUndo()
Definition: documen9.cxx:61
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1905
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC void SetScenarioData(SCTAB nTab, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: documen3.cxx:438
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:837
const ScSheetEvents * GetSheetEvents(SCTAB nTab) const
Definition: documen3.cxx:661
OUString GetLinkOpt(SCTAB nTab) const
Definition: documen3.cxx:523
SC_DLLPUBLIC bool SetOptimalHeight(sc::RowHeightContext &rCxt, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bApi)
Definition: document.cxx:4267
SC_DLLPUBLIC void AddPrintRange(SCTAB nTab, const ScRange &rNew)
Adds a new print ranges.
Definition: document.cxx:6297
void FillTabMarked(SCTAB nSrcTab, const ScMarkData &rMark, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: document.cxx:3325
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6050
void GetSearchAndReplaceStart(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow)
Definition: documen3.cxx:1213
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:492
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC void ClearPrintRanges(SCTAB nTab)
Removes all print ranges.
Definition: document.cxx:6291
bool HasLink(std::u16string_view rDoc, std::u16string_view rFilter, std::u16string_view rOptions) const
Definition: documen3.cxx:552
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:6303
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:469
void FillTab(const ScRange &rSrcArea, const ScMarkData &rMark, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: document.cxx:3257
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:473
bool IsInVBAMode() const
Definition: document.cxx:6477
void ApplySelectionLineStyle(const ScMarkData &rMark, const ::editeng::SvxBorderLine *pLine, bool bColorOnly)
Definition: document.cxx:4852
SC_DLLPUBLIC bool HasData(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen5.cxx:529
SC_DLLPUBLIC void SetDrawPageSize(SCTAB nTab)
Definition: documen9.cxx:203
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1084
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:375
SC_DLLPUBLIC void SetRepeatRowRange(SCTAB nTab, std::optional< ScRange > oNew)
Definition: document.cxx:6315
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
Definition: documen3.cxx:502
SC_DLLPUBLIC bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, HasAttrFlags nMask) const
Definition: document.cxx:5161
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:1010
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:2041
SC_DLLPUBLIC void ApplyPatternIfNumberformatIncompatible(const ScRange &rRange, const ScMarkData &rMark, const ScPatternAttr &rPattern, SvNumFormatType nNewType)
Definition: document.cxx:4777
void FindAreaPos(SCCOL &rCol, SCROW &rRow, SCTAB nTab, ScMoveDirection eDirection) const
Definition: document.cxx:6078
const OUString & GetCodeName() const
Definition: document.hxx:609
SC_DLLPUBLIC sal_uLong AddValidationEntry(const ScValidationData &rNew)
Definition: documen4.cxx:719
SC_DLLPUBLIC void ExtendOverlapped(SCCOL &rStartCol, SCROW &rStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5466
sal_uLong GetLinkRefreshDelay(SCTAB nTab) const
Definition: documen3.cxx:537
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
Definition: documen3.cxx:544
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:467
SC_DLLPUBLIC void SetActiveScenario(SCTAB nTab, bool bActive)
Definition: documen3.cxx:886
bool SearchAndReplace(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow, SCTAB &rTab, const ScMarkData &rMark, ScRangeList &rMatchedRanges, OUString &rUndoStr, ScDocument *pUndoDoc, bool &bMatchedRangesWereClamped)
Definition: documen3.cxx:1307
std::unique_ptr< ScPrintRangeSaver > CreatePrintRangeSaver() const
Definition: document.cxx:6321
SC_DLLPUBLIC bool IsEmptyData(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:6060
static bool IsEmptyCellSearch(const SvxSearchItem &rSearchItem)
Definition: documen3.cxx:1300
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:890
SC_DLLPUBLIC OUString GetLinkDoc(SCTAB nTab) const
Definition: documen3.cxx:509
bool IsLinked(SCTAB nTab) const
Definition: documen3.cxx:486
SC_DLLPUBLIC CellType GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:3736
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:974
bool IsBlockEmpty(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5288
SC_DLLPUBLIC bool DeleteTab(SCTAB nTab)
Definition: document.cxx:654
SC_DLLPUBLIC void SetRepeatColRange(SCTAB nTab, std::optional< ScRange > oNew)
Definition: document.cxx:6309
SC_DLLPUBLIC bool DeleteTabs(SCTAB nTab, SCTAB nSheets)
Definition: document.cxx:747
SC_DLLPUBLIC sfx2::LinkManager * GetLinkManager()
Definition: documen2.cxx:231
bool IsUndoEnabled() const
Definition: document.hxx:1595
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:204
OUString GetLinkFlt(SCTAB nTab) const
Definition: documen3.cxx:516
void SetClipParam(const ScClipParam &rParam)
Definition: document.cxx:2572
SC_DLLPUBLIC void SetScenario(SCTAB nTab, bool bFlag)
Definition: documen3.cxx:426
void RemoveManualBreaks(SCTAB nTab)
Definition: document.cxx:6216
bool IsChartListenerCollectionNeedsUpdate() const
Definition: document.hxx:2239
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4719
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1936
SC_DLLPUBLIC void SetVisible(SCTAB nTab, bool bVisible)
Definition: document.cxx:884
SC_DLLPUBLIC bool IsActiveScenario(SCTAB nTab) const
Definition: documen3.cxx:880
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
bool NeedsObject() const
Definition: editutil.hxx:102
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:619
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:227
const std::vector< editeng::MisspellRanges > * GetAutoSpellData(SCCOL nPosX, SCROW nPosY)
Definition: gridwin.cxx:5958
void SetCellSelectionPixel(int nType, int nPixelX, int nPixelY)
Update the cell selection according to what handles have been dragged.
Definition: gridwin4.cxx:1765
void ResetAutoSpellForContentChange()
Definition: gridwin.cxx:5944
void GetCellSelection(std::vector< tools::Rectangle > &rLogicRects)
Get the cell selection, coordinates are in logic units.
Definition: gridwin.cxx:6562
void SetAutoSpellData(SCCOL nPosX, SCROW nPosY, const std::vector< editeng::MisspellRanges > *pRanges)
Definition: gridwin.cxx:5950
bool InsideVisibleRange(SCCOL nPosX, SCROW nPosY)
Definition: gridwin.cxx:5969
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:1398
SfxItemSet & GetItemSet()
Definition: patattr.hxx:192
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:593
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:535
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:690
bool TabKeyInput(const KeyEvent &rKEvt)
Definition: tabvwsh4.cxx:1210
void UpdatePageBreakData(bool bForcePaint=false)
Definition: tabview2.cxx:1590
void TabChanged(bool bSameTabButMoved=false)
Called after moving, copying, inserting or deleting a sheet.
Definition: tabview5.cxx:280
void AlignToCursor(SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, const ScSplitPos *pWhich=nullptr)
Definition: tabview3.cxx:917
void DoneBlockMode(bool bContinue=false)
Definition: tabview2.cxx:509
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1553
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1708
vcl::Window * GetFrameWin() const
Definition: tabview.hxx:596
void PaintArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScUpdateMode eMode=ScUpdateMode::All)
Definition: tabview3.cxx:2331
static void UpdateInputLine()
Definition: tabview3.cxx:3059
ScViewData & GetViewData()
Definition: tabview.hxx:344
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:878
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:363
void Unmark()
Definition: tabview3.cxx:1744
SC_DLLPUBLIC void CellContentChanged()
Definition: tabview3.cxx:513
ScDrawView * GetScDrawView()
Definition: tabview.hxx:352
void MarkDataChanged()
Definition: tabview3.cxx:1767
void InitOwnBlockMode(const ScRange &rMarkRange)
Definition: tabview2.cxx:432
void UpdateScrollBars(HeaderType eHeaderType=BOTH_HEADERS)
Definition: tabview4.cxx:389
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1819
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:550
virtual formula::FormulaToken * AddOpCode(OpCode eCode) override
Definition: token.cxx:2265
formula::FormulaToken * AddDoubleReference(const ScComplexRefData &rRef)
Definition: token.cxx:2282
bool GetAdjacentExtendOfOuterFuncRefs(SCCOLROW &nExtend, const ScAddress &rPos, ScDirection)
Determines the extent of direct adjacent references.
Definition: token.cxx:2337
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3140
const ScViewOptions & GetOptions() const
Definition: viewdata.hxx:554
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3146
const Fraction & GetZoomY() const
Definition: viewdata.hxx:460
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void InsertTab(SCTAB nTab)
Definition: viewdata.cxx:882
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:3162
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:2785
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:1182
Point GetScrPos(SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich, bool bAllowNeg=false, SCTAB nForTab=-1) const
Definition: viewdata.cxx:2380
const Fraction & GetZoomX() const
Definition: viewdata.hxx:459
ScAddress GetCurPos() const
Definition: viewdata.cxx:4119
double GetPPTX() const
Definition: viewdata.hxx:468
SfxBindings & GetBindings()
Definition: viewdata.cxx:3134
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:2317
bool SelectionEditable(bool *pOnlyNotBecauseOfMatrix=nullptr)
Definition: viewfunc.cxx:274
bool AppendTable(const OUString &rName, bool bRecord=true)
Definition: viewfun2.cxx:2436
bool GetAutoSumArea(ScRangeList &rRangeList)
Definition: viewfun2.cxx:510
void RemoveManualBreaks()
Definition: viewfun2.cxx:1004
void FillTab(InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bAsLink)
Definition: viewfun2.cxx:1678
void AdjustPrintZoom()
Definition: viewfun2.cxx:1035
SC_DLLPUBLIC void FillSimple(FillDir eDir)
Definition: viewfun2.cxx:1395
bool RemoveMerge()
Definition: viewfun2.cxx:1345
void EnterData(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const EditTextObject *pData=nullptr, bool bMatrixExpand=false)
Definition: viewfunc.cxx:384
SC_DLLPUBLIC void DeletePageBreak(bool bColumn, bool bRecord=true, const ScAddress *pPos=nullptr, bool bSetModified=true)
Definition: viewfun2.cxx:987
void ApplyUserItemSet(const SfxItemSet &rItemSet)
Definition: viewfunc.cxx:1396
void SetPrintRanges(bool bEntireSheet, const OUString *pPrint, const OUString *pRepCol, const OUString *pRepRow, bool bAddPrint)
Definition: viewfun2.cxx:1043
void FillSeries(FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd, double fStart, double fStep, double fMax)
Definition: viewfun2.cxx:1444
void TransliterateText(TransliterationFlags nType)
Definition: viewfun2.cxx:1882
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:3356
void SetPrintZoom(sal_uInt16 nScale)
Definition: viewfun2.cxx:1028
SC_DLLPUBLIC void InsertPageBreak(bool bColumn, bool bRecord=true, const ScAddress *pPos=nullptr, bool bSetModified=true)
Definition: viewfun2.cxx:970
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:2678
void EnterValue(SCCOL nCol, SCROW nRow, SCTAB nTab, const double &rValue)
Definition: viewfunc.cxx:669
bool SetTabBgColor(const Color &rColor, SCTAB nTabNr)
Definition: viewfun2.cxx:2658
void ApplySelectionPattern(const ScPatternAttr &rAttr, bool bCursorOnly=false)
Definition: viewfunc.cxx:1227
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:1467
void DeleteTable(SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2467
SC_DLLPUBLIC const ScPatternAttr * GetSelectionPattern()
Definition: viewfunc.cxx:911
void MakeScenario(const OUString &rName, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: viewfun2.cxx:2330
ScAutoFormatData * CreateAutoFormatData()
Definition: viewfun2.cxx:1903
void ImportTables(ScDocShell *pSrcShell, SCTAB nCount, const SCTAB *pSrcTabs, bool bLink, SCTAB nTab)
Definition: viewfun2.cxx:2725
void HideTable(const ScMarkData &rMark, SCTAB nTabToSelect=-1)
Definition: viewfun2.cxx:3237
bool MergeCells(bool bApi, bool &rDoContents, bool bCenter)
Definition: viewfun2.cxx:1179
bool AdjustBlockHeight(bool bPaint=true, ScMarkData *pMarkData=nullptr)
Definition: viewfun2.cxx:115
void ShowTable(const std::vector< OUString > &rNames)
Definition: viewfun2.cxx:3202
void Solve(const ScSolveParam &rParam)
Definition: viewfun2.cxx:2247
void AutoFormat(sal_uInt16 nFormatNo)
Definition: viewfun2.cxx:1924
void MoveTable(sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString *pNewTabName=nullptr)
Definition: viewfun2.cxx:2846
void InsertSpecialChar(const OUString &rStr, const vcl::Font &rFont)
Definition: viewfun2.cxx:3287
static void UpdateLineAttrs(::editeng::SvxBorderLine &rLine, const ::editeng::SvxBorderLine *pDestLine, const ::editeng::SvxBorderLine *pSrcLine, bool bColor)
Definition: viewfun2.cxx:3321
void EnterBlock(const OUString &rString, const EditTextObject *pData)
Definition: viewfun2.cxx:881
void InsertTables(std::vector< OUString > &aNames, SCTAB nTab, SCTAB nCount, bool bRecord=true)
Definition: viewfun2.cxx:2394
void ApplyAttr(const SfxPoolItem &rAttrItem, bool bAdjustBlockHeight=true)
Definition: viewfunc.cxx:1086
bool TestRemoveMerge()
Definition: viewfun2.cxx:1306
bool RenameTable(const OUString &rName, SCTAB nTabNr)
Definition: viewfun2.cxx:2645
void OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth)
Definition: viewfunc.cxx:1697
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:871
bool SearchAndReplace(const SvxSearchItem *pSearchItem, bool bAddUndo, bool bIsApi)
Definition: viewfun2.cxx:1942
void ApplyAttributes(const SfxItemSet *pDialogSet, const SfxItemSet *pOldSet, bool bAdjustBlockHeight=true)
Definition: viewfunc.cxx:974
void InsertTableLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, std::u16string_view rTabName)
Definition: viewfun2.cxx:2691
bool TestMergeCells()
Definition: viewfun2.cxx:1162
void ConvertFormulaToValue()
Definition: viewfun2.cxx:1869
void ExtendScenario()
Definition: viewfun2.cxx:2351
bool InsertTable(const OUString &rName, SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2381
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:3459
void UseScenario(const OUString &rName)
Definition: viewfun2.cxx:2369
bool AdjustRowHeight(SCROW nStartRow, SCROW nEndRow, bool bApi)
Definition: viewfun2.cxx:193
bool GetOption(ScViewOption eOpt) const
Definition: viewopti.hxx:86
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 SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxChildWindow * GetChildWindow(sal_uInt16)
SfxFrame & GetFrame() const
virtual SfxObjectShell * GetObjectShell() override
void ShowChildWindow(sal_uInt16, bool bVisible=true)
virtual void libreOfficeKitViewCallback(int nType, const OString &pPayload) const override
void setTiledSearching(bool bTiledSearching)
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, bool bMatchedRangesWereClamped)
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
OString finishAndGetAsOString()
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:2720
#define SC_DOC_NEW
Definition: document.hxx:248
@ SCDOCMODE_CLIP
Definition: document.hxx:257
@ SCDOCMODE_UNDO
Definition: document.hxx:258
OUString sName
@ SC_MOVE_DOWN
Definition: global.hxx:330
CellType
Definition: global.hxx:272
@ CELLTYPE_EDIT
Definition: global.hxx:277
@ CELLTYPE_FORMULA
Definition: global.hxx:276
constexpr OUStringLiteral STRING_SCAPP
Definition: global.hxx:58
ScPasteFunc
Definition: global.hxx:181
@ INS_NONE
Definition: global.hxx:295
InsertDeleteFlags
Definition: global.hxx:149
@ ATTRIB
Internal use only (d&d undo): do not delete caption objects of cell notes.
FillDateCmd
Definition: global.hxx:334
ScScenarioFlags
Definition: global.hxx:226
ScDirection
Definition: global.hxx:343
@ DIR_LEFT
Definition: global.hxx:347
@ DIR_TOP
Definition: global.hxx:346
FillCmd
Definition: global.hxx:317
FillDir
Definition: global.hxx:309
@ FILL_TO_TOP
Definition: global.hxx:312
@ FILL_TO_RIGHT
Definition: global.hxx:311
@ FILL_TO_LEFT
Definition: global.hxx:313
@ FILL_TO_BOTTOM
Definition: global.hxx:310
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
void NotifyIfChangesListeners(const ScDocShell &rDocShell, const ScRange &rRange, const OUString &rType=OUString("cell-change"))
Definition: docsh.hxx:506
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:498
bool getMustPropagateChangesModel(ScModelObj *pModelObj)
Definition: docsh.hxx:493
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
#define stringstream
Definition: utils.hxx:45
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:3343
static bool lcl_extendMergeRange(ScCellMergeOption &rOption, const ScRange &rRange)
Definition: viewfun2.cxx:1319
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:47
const char * pChar
SvNumFormatType