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 Code 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 <config_features.h>
21 
22 #include <com/sun/star/i18n/TextConversionOption.hpp>
23 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
24 
25 #include <scitems.hxx>
26 #include <sfx2/viewfrm.hxx>
27 
28 #include <basic/sberrors.hxx>
29 #include <comphelper/lok.hxx>
30 #include <comphelper/propertysequence.hxx>
31 #include <svl/stritem.hxx>
32 #include <svl/zforlist.hxx>
33 #include <svl/zformat.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/request.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/weld.hxx>
38 #include <svx/svxdlg.hxx>
39 #include <sot/formats.hxx>
40 #include <svx/postattr.hxx>
41 #include <editeng/fontitem.hxx>
42 #include <svx/clipfmtitem.hxx>
43 #include <svx/hlnkitem.hxx>
44 #include <basic/sbxcore.hxx>
45 #include <editeng/editview.hxx>
46 #include <svtools/cliplistener.hxx>
47 
48 #include <cellsh.hxx>
49 #include <ftools.hxx>
50 #include <sc.hrc>
51 #include <document.hxx>
52 #include <patattr.hxx>
53 #include <scmod.hxx>
54 #include <tabvwsh.hxx>
55 #include <uiitems.hxx>
56 #include <reffact.hxx>
57 #include <inputhdl.hxx>
58 #include <transobj.hxx>
59 #include <drwtrans.hxx>
60 #include <docfunc.hxx>
61 #include <editable.hxx>
62 #include <dpobject.hxx>
63 #include <dpsave.hxx>
64 #include <spellparam.hxx>
65 #include <postit.hxx>
66 #include <dpsdbtab.hxx>
67 #include <dpshttab.hxx>
68 #include <dbdata.hxx>
69 #include <docsh.hxx>
70 #include <cliputil.hxx>
71 #include <markdata.hxx>
72 #include <colorscale.hxx>
73 #include <condformatdlg.hxx>
74 #include <attrib.hxx>
75 #include <condformatdlgitem.hxx>
76 
77 #include <globstr.hrc>
78 #include <scresid.hxx>
79 #include <scui_def.hxx>
80 #include <scabstdlg.hxx>
81 #include <tokenstringcontext.hxx>
82 #include <cellvalue.hxx>
83 #include <tokenarray.hxx>
84 #include <formulacell.hxx>
85 #include <gridwin.hxx>
86 #include <searchresults.hxx>
87 
88 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
89 #include <com/sun/star/lang/XInitialization.hpp>
90 #include <com/sun/star/beans/XPropertySet.hpp>
91 #include <com/sun/star/uno/XComponentContext.hpp>
92 #include <cppuhelper/bootstrap.hxx>
93 
94 #include <memory>
95 
96 using namespace ::com::sun::star;
97 using namespace ::com::sun::star::beans;
98 using namespace ::com::sun::star::uno;
99 
100 namespace{
FlagsFromString(const OUString & rFlagsStr,InsertDeleteFlags nFlagsMask=InsertDeleteFlags::CONTENTS|InsertDeleteFlags::ATTRIB)101 InsertDeleteFlags FlagsFromString(const OUString& rFlagsStr,
102     InsertDeleteFlags nFlagsMask = InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ATTRIB)
103 {
104     OUString aFlagsStr = rFlagsStr.toAsciiUpperCase();
105     InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
106 
107     for (sal_Int32 i=0 ; i < aFlagsStr.getLength(); ++i)
108     {
109         switch (aFlagsStr[i])
110         {
111             case 'A': return    InsertDeleteFlags::ALL;
112             case 'S': nFlags |= InsertDeleteFlags::STRING   & nFlagsMask; break;
113             case 'V': nFlags |= InsertDeleteFlags::VALUE    & nFlagsMask; break;
114             case 'D': nFlags |= InsertDeleteFlags::DATETIME & nFlagsMask; break;
115             case 'F': nFlags |= InsertDeleteFlags::FORMULA  & nFlagsMask; break;
116             case 'N': nFlags |= InsertDeleteFlags::NOTE     & nFlagsMask; break;
117             case 'T': nFlags |= InsertDeleteFlags::ATTRIB   & nFlagsMask; break;
118             case 'O': nFlags |= InsertDeleteFlags::OBJECTS  & nFlagsMask; break;
119         }
120     }
121     return nFlags;
122 }
123 
FlagsToString(InsertDeleteFlags nFlags,InsertDeleteFlags nFlagsMask=InsertDeleteFlags::CONTENTS|InsertDeleteFlags::ATTRIB)124 OUString FlagsToString( InsertDeleteFlags nFlags,
125     InsertDeleteFlags nFlagsMask = InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ATTRIB )
126 {
127     OUString  aFlagsStr;
128 
129     if( nFlags == InsertDeleteFlags::ALL )
130     {
131         aFlagsStr = "A";
132     }
133     else
134     {
135         nFlags &= nFlagsMask;
136 
137         if( nFlags & InsertDeleteFlags::STRING )    aFlagsStr += "S";
138         if( nFlags & InsertDeleteFlags::VALUE )     aFlagsStr += "V";
139         if( nFlags & InsertDeleteFlags::DATETIME )  aFlagsStr += "D";
140         if( nFlags & InsertDeleteFlags::FORMULA )   aFlagsStr += "F";
141         if( nFlags & InsertDeleteFlags::NOTE )      aFlagsStr += "N";
142         if( nFlags & InsertDeleteFlags::ATTRIB )    aFlagsStr += "T";
143         if( nFlags & InsertDeleteFlags::OBJECTS )   aFlagsStr += "O";
144     }
145     return aFlagsStr;
146 }
147 
SetTabNoAndCursor(const ScViewData * rViewData,const OUString & rCellId)148 void SetTabNoAndCursor( const ScViewData* rViewData, const OUString& rCellId )
149 {
150     ScTabViewShell* pTabViewShell = rViewData->GetViewShell();
151     assert(pTabViewShell);
152     const ScDocument& rDoc = rViewData->GetDocShell()->GetDocument();
153     std::vector<sc::NoteEntry> aNotes;
154     rDoc.GetAllNoteEntries(aNotes);
155 
156     sal_uInt32 nId = rCellId.toUInt32();
157     auto lComp = [nId](const sc::NoteEntry& rNote) { return rNote.mpNote->GetId() == nId; };
158 
159     const auto& aFoundNoteIt = std::find_if(aNotes.begin(), aNotes.end(), lComp);
160     if (aFoundNoteIt != aNotes.end())
161     {
162         ScAddress aFoundPos = aFoundNoteIt->maPos;
163         pTabViewShell->SetTabNo(aFoundPos.Tab());
164         pTabViewShell->SetCursor(aFoundPos.Col(), aFoundPos.Row());
165     }
166 }
167 }
168 
ExecuteEdit(SfxRequest & rReq)169 void ScCellShell::ExecuteEdit( SfxRequest& rReq )
170 {
171     ScModule*           pScMod      = SC_MOD();
172     ScTabViewShell* pTabViewShell   = GetViewData()->GetViewShell();
173     SfxBindings&        rBindings   = pTabViewShell->GetViewFrame()->GetBindings();
174     const SfxItemSet*   pReqArgs    = rReq.GetArgs();
175     sal_uInt16              nSlot       = rReq.GetSlot();
176 
177     pTabViewShell->HideListBox();                   // Autofilter-DropDown-Listbox
178 
179     // finish input
180     if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
181     {
182         switch ( nSlot )
183         {
184             case FID_DEFINE_NAME:
185             case FID_ADD_NAME:
186             case FID_USE_NAME:
187             case FID_INSERT_NAME:
188             case SID_SPELL_DIALOG:
189             case SID_HANGUL_HANJA_CONVERSION:
190             case SID_OPENDLG_CONDFRMT:
191             case SID_OPENDLG_CURRENTCONDFRMT:
192             case SID_OPENDLG_COLORSCALE:
193             case SID_OPENDLG_DATABAR:
194                 pScMod->InputEnterHandler();
195                 pTabViewShell->UpdateInputHandler();
196             break;
197 
198             default:
199             break;
200         }
201     }
202 
203     switch ( nSlot )
204     {
205 
206         //  insert / delete cells / rows / columns
207 
208         case FID_INS_ROW:
209         case FID_INS_ROWS_BEFORE:
210             pTabViewShell->InsertCells(INS_INSROWS_BEFORE);
211             rReq.Done();
212             break;
213 
214         case FID_INS_COLUMN:
215         case FID_INS_COLUMNS_BEFORE:
216             pTabViewShell->InsertCells(INS_INSCOLS_BEFORE);
217             rReq.Done();
218             break;
219 
220         case FID_INS_ROWS_AFTER:
221             pTabViewShell->InsertCells(INS_INSROWS_AFTER);
222             rReq.Done();
223             break;
224 
225         case FID_INS_COLUMNS_AFTER:
226             pTabViewShell->InsertCells(INS_INSCOLS_AFTER);
227             rReq.Done();
228             break;
229 
230         case FID_INS_CELLSDOWN:
231             pTabViewShell->InsertCells(INS_CELLSDOWN);
232             rReq.Done();
233             break;
234 
235         case FID_INS_CELLSRIGHT:
236             pTabViewShell->InsertCells(INS_CELLSRIGHT);
237             rReq.Done();
238             break;
239 
240         case SID_DEL_ROWS:
241             pTabViewShell->DeleteCells( DelCellCmd::Rows );
242             rReq.Done();
243             break;
244 
245         case SID_DEL_COLS:
246             pTabViewShell->DeleteCells( DelCellCmd::Cols );
247             rReq.Done();
248             break;
249 
250         case FID_INS_CELL:
251             {
252                 InsCellCmd eCmd=INS_NONE;
253 
254                 if ( pReqArgs )
255                 {
256                     const SfxPoolItem* pItem;
257                     OUString aFlags;
258 
259                     if( pReqArgs->HasItem( FID_INS_CELL, &pItem ) )
260                         aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
261                     if( !aFlags.isEmpty() )
262                     {
263                         switch( aFlags[0] )
264                         {
265                             case 'V': eCmd = INS_CELLSDOWN ;break;
266                             case '>': eCmd = INS_CELLSRIGHT ;break;
267                             case 'R': eCmd = INS_INSROWS_BEFORE ;break;
268                             case 'C': eCmd = INS_INSCOLS_BEFORE ;break;
269                         }
270                     }
271                 }
272                 else
273                 {
274                     if ( GetViewData()->SimpleColMarked() )
275                         eCmd = INS_INSCOLS_BEFORE;
276                     else if ( GetViewData()->SimpleRowMarked() )
277                         eCmd = INS_INSROWS_BEFORE;
278                     else
279                     {
280                         ScDocument* pDoc = GetViewData()->GetDocument();
281                         bool bTheFlag=(pDoc->GetChangeTrack()!=nullptr);
282 
283                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
284 
285                         ScopedVclPtr<AbstractScInsertCellDlg> pDlg(pFact->CreateScInsertCellDlg(pTabViewShell->GetFrameWeld(), bTheFlag));
286                         if (pDlg->Execute() == RET_OK)
287                             eCmd = pDlg->GetInsCellCmd();
288                     }
289                 }
290 
291                 if (eCmd!=INS_NONE)
292                 {
293                     pTabViewShell->InsertCells( eCmd );
294 
295                     if( ! rReq.IsAPI() )
296                     {
297                         OUString aParam;
298 
299                         switch( eCmd )
300                         {
301                             case INS_CELLSDOWN: aParam = "V"; break;
302                             case INS_CELLSRIGHT: aParam = ">"; break;
303                             case INS_INSROWS_BEFORE: aParam = "R"; break;
304                             case INS_INSCOLS_BEFORE: aParam = "C"; break;
305                             default:
306                             {
307                                 // added to avoid warnings
308                             }
309                         }
310                         rReq.AppendItem( SfxStringItem( FID_INS_CELL, aParam ) );
311                         rReq.Done();
312                     }
313                 }
314             }
315             break;
316 
317         case FID_DELETE_CELL:
318             {
319                 DelCellCmd eCmd = DelCellCmd::NONE;
320 
321                 if ( pReqArgs )
322                 {
323                     const SfxPoolItem* pItem;
324                     OUString aFlags;
325 
326                     if( pReqArgs->HasItem( FID_DELETE_CELL, &pItem ) )
327                         aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
328                     if( !aFlags.isEmpty() )
329                     {
330                         switch( aFlags[0] )
331                         {
332                             case 'U': eCmd = DelCellCmd::CellsUp ;break;
333                             case 'L': eCmd = DelCellCmd::CellsLeft ;break;
334                             case 'R': eCmd = DelCellCmd::Rows ;break;
335                             case 'C': eCmd = DelCellCmd::Cols ;break;
336                         }
337                     }
338                 }
339                 else
340                 {
341                     if ( GetViewData()->SimpleColMarked() )
342                         eCmd = DelCellCmd::Cols;
343                     else if ( GetViewData()->SimpleRowMarked() )
344                         eCmd = DelCellCmd::Rows;
345                     else
346                     {
347                         ScRange aRange;
348                         ScDocument* pDoc = GetViewData()->GetDocument();
349                         bool bTheFlag=GetViewData()->IsMultiMarked() ||
350                             (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE_FILTERED) ||
351                             (pDoc->GetChangeTrack() != nullptr);
352 
353                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
354 
355                         ScopedVclPtr<AbstractScDeleteCellDlg> pDlg(pFact->CreateScDeleteCellDlg( pTabViewShell->GetFrameWeld(), bTheFlag ));
356 
357                         if (pDlg->Execute() == RET_OK)
358                             eCmd = pDlg->GetDelCellCmd();
359                     }
360                 }
361 
362                 if (eCmd != DelCellCmd::NONE )
363                 {
364                     pTabViewShell->DeleteCells( eCmd );
365 
366                     if( ! rReq.IsAPI() )
367                     {
368                         OUString aParam;
369 
370                         switch( eCmd )
371                         {
372                             case DelCellCmd::CellsUp: aParam = "U"; break;
373                             case DelCellCmd::CellsLeft: aParam = "L"; break;
374                             case DelCellCmd::Rows: aParam = "R"; break;
375                             case DelCellCmd::Cols: aParam = "C"; break;
376                             default:
377                             {
378                                 // added to avoid warnings
379                             }
380                         }
381                         rReq.AppendItem( SfxStringItem( FID_DELETE_CELL, aParam ) );
382                         rReq.Done();
383                     }
384                 }
385             }
386             break;
387 
388         //  delete contents from cells
389 
390         case SID_DELETE_CONTENTS:
391             pTabViewShell->DeleteContents( InsertDeleteFlags::CONTENTS );
392             rReq.Done();
393             break;
394 
395         case SID_DELETE:
396             {
397                 InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
398 
399                 if ( pReqArgs!=nullptr && pTabViewShell->SelectionEditable() )
400                 {
401                     const   SfxPoolItem* pItem;
402                     OUString aFlags('A');
403 
404                     if( pReqArgs->HasItem( SID_DELETE, &pItem ) )
405                         aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
406 
407                     nFlags |= FlagsFromString(aFlags, InsertDeleteFlags::ALL);
408                 }
409                 else
410                 {
411                     ScEditableTester aTester( pTabViewShell );
412                     if (aTester.IsEditable())
413                     {
414                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
415 
416                         ScopedVclPtr<AbstractScDeleteContentsDlg> pDlg(pFact->CreateScDeleteContentsDlg(pTabViewShell->GetFrameWeld()));
417                         ScDocument* pDoc = GetViewData()->GetDocument();
418                         SCTAB nTab = GetViewData()->GetTabNo();
419                         if ( pDoc->IsTabProtected(nTab) )
420                             pDlg->DisableObjects();
421                         if (pDlg->Execute() == RET_OK)
422                         {
423                             nFlags = pDlg->GetDelContentsCmdBits();
424                         }
425                     }
426                     else
427                         pTabViewShell->ErrorMessage(aTester.GetMessageId());
428                 }
429 
430                 if( nFlags != InsertDeleteFlags::NONE )
431                 {
432                     pTabViewShell->DeleteContents( nFlags );
433 
434                     if( ! rReq.IsAPI() )
435                     {
436                         OUString aFlags = FlagsToString( nFlags, InsertDeleteFlags::ALL );
437 
438                         rReq.AppendItem( SfxStringItem( SID_DELETE, aFlags ) );
439                         rReq.Done();
440                     }
441                 }
442             }
443             break;
444 
445         //  fill...
446 
447         case FID_FILL_TO_BOTTOM:
448             pTabViewShell->FillSimple( FILL_TO_BOTTOM );
449             rReq.Done();
450             break;
451 
452         case FID_FILL_TO_RIGHT:
453             pTabViewShell->FillSimple( FILL_TO_RIGHT );
454             rReq.Done();
455             break;
456 
457         case FID_FILL_TO_TOP:
458             pTabViewShell->FillSimple( FILL_TO_TOP );
459             rReq.Done();
460             break;
461 
462         case FID_FILL_TO_LEFT:
463             pTabViewShell->FillSimple( FILL_TO_LEFT );
464             rReq.Done();
465             break;
466 
467         case FID_FILL_TAB:
468             {
469                 InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
470                 ScPasteFunc nFunction = ScPasteFunc::NONE;
471                 bool bSkipEmpty = false;
472                 bool bAsLink    = false;
473 
474                 if ( pReqArgs!=nullptr && pTabViewShell->SelectionEditable() )
475                 {
476                     const   SfxPoolItem* pItem;
477                     OUString aFlags('A');
478 
479                     if( pReqArgs->HasItem( FID_FILL_TAB, &pItem ) )
480                         aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
481 
482                     nFlags |= FlagsFromString(aFlags);
483                 }
484                 else
485                 {
486                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
487 
488                     ScopedVclPtr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg(pTabViewShell->GetFrameWeld(),
489                                                                                                     new OUString(ScResId(STR_FILL_TAB))));
490                     pDlg->SetFillMode(true);
491 
492                     if (pDlg->Execute() == RET_OK)
493                     {
494                         nFlags     = pDlg->GetInsContentsCmdBits();
495                         nFunction  = pDlg->GetFormulaCmdBits();
496                         bSkipEmpty = pDlg->IsSkipEmptyCells();
497                         bAsLink    = pDlg->IsLink();
498                         //  there is no MoveMode with fill tabs
499                     }
500                 }
501 
502                 if( nFlags != InsertDeleteFlags::NONE )
503                 {
504                     pTabViewShell->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
505 
506                     if( ! rReq.IsAPI() )
507                     {
508                         OUString aFlags = FlagsToString( nFlags );
509 
510                         rReq.AppendItem( SfxStringItem( FID_FILL_TAB, aFlags ) );
511                         rReq.Done();
512                     }
513                 }
514             }
515             break;
516 
517         case FID_FILL_SERIES:
518             {
519                 if (GetViewData()->SelectionForbidsCellFill())
520                     // Slot should be already disabled, but in case it wasn't
521                     // don't even attempt to do the evaluation and popup a
522                     // dialog.
523                     break;
524 
525                 SCCOL nStartCol;
526                 SCROW nStartRow;
527                 SCTAB nStartTab;
528                 SCCOL nEndCol;
529                 SCROW nEndRow;
530                 SCTAB nEndTab;
531                 sal_uInt16 nPossDir = FDS_OPT_NONE;
532                 FillDir     eFillDir     = FILL_TO_BOTTOM;
533                 FillCmd     eFillCmd     = FILL_LINEAR;
534                 FillDateCmd eFillDateCmd = FILL_DAY;
535                 double fStartVal = MAXDOUBLE;
536                 double fIncVal   = 1;
537                 double fMaxVal   = MAXDOUBLE;
538                 bool   bDoIt     = false;
539 
540                 GetViewData()->GetSimpleArea( nStartCol, nStartRow, nStartTab,
541                                               nEndCol, nEndRow, nEndTab );
542 
543                 if( nStartCol!=nEndCol )
544                 {
545                     nPossDir |= FDS_OPT_HORZ;
546                     eFillDir=FILL_TO_RIGHT;
547                 }
548 
549                 if( nStartRow!=nEndRow )
550                 {
551                     nPossDir |= FDS_OPT_VERT;
552                     eFillDir=FILL_TO_BOTTOM;
553                 }
554 
555                 ScDocument*      pDoc = GetViewData()->GetDocument();
556                 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
557 
558                 if( pReqArgs )
559                 {
560                     const SfxPoolItem* pItem;
561                     OUString  aFillDir, aFillCmd, aFillDateCmd;
562                     OUString  aFillStep, aFillStart, aFillMax;
563                     sal_uInt32 nKey;
564                     double  fTmpVal;
565 
566                     if( pReqArgs->HasItem( FID_FILL_SERIES, &pItem ) )
567                         aFillDir = static_cast<const SfxStringItem*>(pItem)->GetValue();
568                     if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
569                         aFillCmd = static_cast<const SfxStringItem*>(pItem)->GetValue();
570                     if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
571                         aFillDateCmd = static_cast<const SfxStringItem*>(pItem)->GetValue();
572                     if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) )
573                         aFillStep = static_cast<const SfxStringItem*>(pItem)->GetValue();
574                     if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
575                         aFillStart = static_cast<const SfxStringItem*>(pItem)->GetValue();
576                     if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
577                         aFillMax = static_cast<const SfxStringItem*>(pItem)->GetValue();
578 
579                     if( !aFillDir.isEmpty() )
580                         switch( aFillDir[0] )
581                         {
582                             case 'B': case 'b': eFillDir=FILL_TO_BOTTOM; break;
583                             case 'R': case 'r': eFillDir=FILL_TO_RIGHT; break;
584                             case 'T': case 't': eFillDir=FILL_TO_TOP; break;
585                             case 'L': case 'l': eFillDir=FILL_TO_LEFT; break;
586                         }
587 
588                     if( !aFillCmd.isEmpty() )
589                         switch( aFillCmd[0] )
590                         {
591                             case 'S': case 's': eFillCmd=FILL_SIMPLE; break;
592                             case 'L': case 'l': eFillCmd=FILL_LINEAR; break;
593                             case 'G': case 'g': eFillCmd=FILL_GROWTH; break;
594                             case 'D': case 'd': eFillCmd=FILL_DATE; break;
595                             case 'A': case 'a': eFillCmd=FILL_AUTO; break;
596                         }
597 
598                     if( !aFillDateCmd.isEmpty() )
599                         switch( aFillDateCmd[0] )
600                         {
601                             case 'D': case 'd': eFillDateCmd=FILL_DAY; break;
602                             case 'W': case 'w': eFillDateCmd=FILL_WEEKDAY; break;
603                             case 'M': case 'm': eFillDateCmd=FILL_MONTH; break;
604                             case 'Y': case 'y': eFillDateCmd=FILL_YEAR; break;
605                         }
606 
607                     nKey = 0;
608                     if( pFormatter->IsNumberFormat( aFillStart, nKey, fTmpVal ))
609                         fStartVal = fTmpVal;
610 
611                     nKey = 0;
612                     if( pFormatter->IsNumberFormat( aFillStep, nKey, fTmpVal ))
613                         fIncVal = fTmpVal;
614 
615                     nKey = 0;
616                     if( pFormatter->IsNumberFormat( aFillMax, nKey, fTmpVal ))
617                         fMaxVal = fTmpVal;
618 
619                     bDoIt   = true;
620 
621                 }
622                 else // (pReqArgs == nullptr) => raise Dialog
623                 {
624                     sal_uInt32 nPrivFormat;
625                     CellType eCellType;
626                     pDoc->GetNumberFormat( nStartCol, nStartRow, nStartTab, nPrivFormat );
627                     pDoc->GetCellType( nStartCol, nStartRow, nStartTab,eCellType );
628                     const SvNumberformat* pPrivEntry = pFormatter->GetEntry( nPrivFormat );
629                     if (!pPrivEntry)
630                     {
631                         OSL_FAIL("Numberformat not found !!!");
632                     }
633                     else
634                     {
635                         SvNumFormatType nPrivType = pPrivEntry->GetType();
636                         if (nPrivType & SvNumFormatType::DATE)
637                         {
638                            eFillCmd=FILL_DATE;
639                         }
640                         else if(eCellType==CELLTYPE_STRING)
641                         {
642                            eFillCmd=FILL_AUTO;
643                         }
644                     }
645 
646                     OUString aStartStr;
647 
648                     //  suggest default Startvalue only, when just 1 row or column
649                     if ( nStartCol == nEndCol || nStartRow == nEndRow )
650                     {
651                         double fInputEndVal = 0.0;
652                         OUString aEndStr;
653 
654                         pDoc->GetInputString( nStartCol, nStartRow, nStartTab, aStartStr);
655                         pDoc->GetValue( nStartCol, nStartRow, nStartTab, fStartVal );
656 
657                         if(eFillDir==FILL_TO_BOTTOM && nStartRow < nEndRow )
658                         {
659                             pDoc->GetInputString( nStartCol, nStartRow+1, nStartTab, aEndStr);
660                             if(!aEndStr.isEmpty())
661                             {
662                                 pDoc->GetValue( nStartCol, nStartRow+1, nStartTab, fInputEndVal);
663                                 fIncVal=fInputEndVal-fStartVal;
664                             }
665                         }
666                         else
667                         {
668                             if(nStartCol < nEndCol)
669                             {
670                                 pDoc->GetInputString( nStartCol+1, nStartRow, nStartTab, aEndStr);
671                                 if(!aEndStr.isEmpty())
672                                 {
673                                     pDoc->GetValue( nStartCol+1, nStartRow, nStartTab, fInputEndVal);
674                                     fIncVal=fInputEndVal-fStartVal;
675                                 }
676                             }
677                         }
678                         if(eFillCmd==FILL_DATE)
679                         {
680                             const Date& rNullDate = pDoc->GetFormatTable()->GetNullDate();
681                             Date aStartDate = rNullDate;
682                             aStartDate.AddDays(fStartVal);
683                             Date aEndDate = rNullDate;
684                             aEndDate.AddDays(fInputEndVal);
685                             double fTempDate=0;
686 
687                             if(aStartDate.GetYear()!=aEndDate.GetYear())
688                             {
689                                 eFillDateCmd = FILL_YEAR;
690                                 fTempDate=aEndDate.GetYear()-aStartDate.GetYear();
691                             }
692                             if(aStartDate.GetMonth()!=aEndDate.GetMonth())
693                             {
694                                 eFillDateCmd = FILL_MONTH;
695                                 fTempDate=fTempDate*12+aEndDate.GetMonth()-aStartDate.GetMonth();
696                             }
697                             if(aStartDate.GetDay()==aEndDate.GetDay())
698                             {
699                                 fIncVal=fTempDate;
700                             }
701                         }
702                     }
703                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
704 
705                     ScopedVclPtr<AbstractScFillSeriesDlg> pDlg(pFact->CreateScFillSeriesDlg( pTabViewShell->GetFrameWeld(),
706                                                             *pDoc,
707                                                             eFillDir, eFillCmd, eFillDateCmd,
708                                                             aStartStr, fIncVal, fMaxVal,
709                                                             nPossDir));
710 
711                     if ( nStartCol != nEndCol && nStartRow != nEndRow )
712                     {
713                         pDlg->SetEdStartValEnabled(false);
714                     }
715 
716                     if ( pDlg->Execute() == RET_OK )
717                     {
718                         eFillDir        = pDlg->GetFillDir();
719                         eFillCmd        = pDlg->GetFillCmd();
720                         eFillDateCmd    = pDlg->GetFillDateCmd();
721 
722                         if(eFillCmd==FILL_AUTO)
723                         {
724                             OUString aStr = pDlg->GetStartStr();
725                             if(!aStr.isEmpty())
726                                 pTabViewShell->EnterData( nStartCol, nStartRow, nStartTab, aStr );
727                         }
728                         fStartVal       = pDlg->GetStart();
729                         fIncVal         = pDlg->GetStep();
730                         fMaxVal         = pDlg->GetMax();
731                         bDoIt           = true;
732                     }
733                 }
734 
735                 if( bDoIt )
736                 {
737                     //nScFillModeMouseModifier = 0; // no Ctrl/Copy
738                     pTabViewShell->FillSeries( eFillDir, eFillCmd, eFillDateCmd, fStartVal, fIncVal, fMaxVal );
739 
740                     if( ! rReq.IsAPI() )
741                     {
742                         OUString  aPara;
743                         Color*  pColor=nullptr;
744 
745                         switch( eFillDir )
746                         {
747                         case FILL_TO_BOTTOM:    aPara = "B"; break;
748                         case FILL_TO_RIGHT:     aPara = "R"; break;
749                         case FILL_TO_TOP:       aPara = "T"; break;
750                         case FILL_TO_LEFT:      aPara = "L"; break;
751                         default: break;
752                         }
753                         rReq.AppendItem( SfxStringItem( FID_FILL_SERIES, aPara ) );
754 
755                         switch( eFillCmd )
756                         {
757                         case FILL_SIMPLE:       aPara = "S"; break;
758                         case FILL_LINEAR:       aPara = "L"; break;
759                         case FILL_GROWTH:       aPara = "G"; break;
760                         case FILL_DATE:         aPara = "D"; break;
761                         case FILL_AUTO:         aPara = "A"; break;
762                         default: break;
763                         }
764                         rReq.AppendItem( SfxStringItem( FN_PARAM_1, aPara ) );
765 
766                         switch( eFillDateCmd )
767                         {
768                         case FILL_DAY:          aPara = "D"; break;
769                         case FILL_WEEKDAY:      aPara = "W"; break;
770                         case FILL_MONTH:        aPara = "M"; break;
771                         case FILL_YEAR:         aPara = "Y"; break;
772                         default: break;
773                         }
774                         rReq.AppendItem( SfxStringItem( FN_PARAM_2, aPara ) );
775 
776                         sal_uInt32 nFormatKey = pFormatter->GetStandardFormat(SvNumFormatType::NUMBER,
777                                     ScGlobal::eLnge );
778 
779                         pFormatter->GetOutputString( fIncVal, nFormatKey, aPara, &pColor );
780                         rReq.AppendItem( SfxStringItem( FN_PARAM_3, aPara ) );
781 
782                         pFormatter->GetOutputString( fStartVal, nFormatKey, aPara, &pColor );
783                         rReq.AppendItem( SfxStringItem( FN_PARAM_4, aPara ) );
784 
785                         pFormatter->GetOutputString( fMaxVal, nFormatKey, aPara, &pColor );
786                         rReq.AppendItem( SfxStringItem( FN_PARAM_5, aPara ) );
787 
788                         rReq.Done();
789                     }
790                 }
791             }
792             break;
793 
794         case FID_FILL_AUTO:
795             {
796                 SCCOL nStartCol;
797                 SCROW nStartRow;
798                 SCCOL nEndCol;
799                 SCROW nEndRow;
800                 SCTAB nStartTab, nEndTab;
801 
802                 GetViewData()->GetFillData( nStartCol, nStartRow, nEndCol, nEndRow );
803                 SCCOL nFillCol = GetViewData()->GetRefEndX();
804                 SCROW nFillRow = GetViewData()->GetRefEndY();
805                 ScDocument* pDoc = GetViewData()->GetDocument();
806 
807                 if( pReqArgs != nullptr )
808                 {
809                     const SfxPoolItem* pItem;
810 
811                     if( pReqArgs->HasItem( FID_FILL_AUTO, &pItem ) )
812                     {
813                         ScAddress aScAddress;
814                         OUString aArg = static_cast<const SfxStringItem*>(pItem)->GetValue();
815 
816                         if( aScAddress.Parse( aArg, pDoc, pDoc->GetAddressConvention() ) & ScRefFlags::VALID )
817                         {
818                             nFillRow = aScAddress.Row();
819                             nFillCol = aScAddress.Col();
820                         }
821                     }
822 
823                     GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
824                                               nEndCol,nEndRow,nEndTab );
825                 }
826                 else    // call via mouse
827                 {
828                     //  not in a merged cell
829 
830                     if ( nStartCol == nEndCol && nStartRow == nEndRow )
831                     {
832                         SCCOL nMergeCol = nStartCol;
833                         SCROW nMergeRow = nStartRow;
834                         if ( GetViewData()->GetDocument()->ExtendMerge(
835                                 nStartCol, nStartRow, nMergeCol, nMergeRow,
836                                 GetViewData()->GetTabNo() ) )
837                         {
838                             if ( nFillCol >= nStartCol && nFillCol <= nMergeCol && nFillRow == nStartRow )
839                                 nFillCol = nStartCol;
840                             if ( nFillRow >= nStartRow && nFillRow <= nMergeRow && nFillCol == nStartCol )
841                                 nFillRow = nStartRow;
842                         }
843                     }
844                 }
845 
846                 if ( nFillCol != nEndCol || nFillRow != nEndRow )
847                 {
848                     if ( nFillCol==nEndCol || nFillRow==nEndRow )
849                     {
850                         FillDir eDir = FILL_TO_BOTTOM;
851                         SCCOLROW nCount = 0;
852 
853                         if ( nFillCol==nEndCol )
854                         {
855                             if ( nFillRow > nEndRow )
856                             {
857                                 eDir = FILL_TO_BOTTOM;
858                                 nCount = nFillRow - nEndRow;
859                             }
860                             else if ( nFillRow < nStartRow )
861                             {
862                                 eDir = FILL_TO_TOP;
863                                 nCount = nStartRow - nFillRow;
864                             }
865                         }
866                         else
867                         {
868                             if ( nFillCol > nEndCol )
869                             {
870                                 eDir = FILL_TO_RIGHT;
871                                 nCount = nFillCol - nEndCol;
872                             }
873                             else if ( nFillCol < nStartCol )
874                             {
875                                 eDir = FILL_TO_LEFT;
876                                 nCount = nStartCol - nFillCol;
877                             }
878                         }
879 
880                         if ( nCount != 0)
881                         {
882                             pTabViewShell->FillAuto( eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount );
883 
884                             if( ! rReq.IsAPI() )
885                             {
886                                 ScAddress aAdr( nFillCol, nFillRow, 0 );
887                                 OUString  aAdrStr(aAdr.Format(ScRefFlags::RANGE_ABS, pDoc, pDoc->GetAddressConvention()));
888 
889                                 rReq.AppendItem( SfxStringItem( FID_FILL_AUTO, aAdrStr ) );
890                                 rReq.Done();
891                             }
892                         }
893 
894                     }
895                     else
896                     {
897                         OSL_FAIL( "Direction not unique for autofill" );
898                     }
899                 }
900             }
901             break;
902         case FID_FILL_SINGLE_EDIT:
903             ExecuteFillSingleEdit();
904             break;
905         case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
906             {
907                 sal_uInt16 nId  = ScRandomNumberGeneratorDialogWrapper::GetChildWindowId();
908                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
909                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
910 
911                 pScMod->SetRefDialog( nId, pWnd == nullptr );
912 
913             }
914             break;
915         case SID_SAMPLING_DIALOG:
916             {
917                 sal_uInt16 nId  = ScSamplingDialogWrapper::GetChildWindowId();
918                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
919                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
920 
921                 pScMod->SetRefDialog( nId, pWnd == nullptr );
922             }
923             break;
924         case SID_DESCRIPTIVE_STATISTICS_DIALOG:
925             {
926                 sal_uInt16 nId  = ScDescriptiveStatisticsDialogWrapper::GetChildWindowId();
927                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
928                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
929 
930                 pScMod->SetRefDialog( nId, pWnd == nullptr );
931             }
932             break;
933         case SID_ANALYSIS_OF_VARIANCE_DIALOG:
934             {
935                 sal_uInt16 nId  = ScAnalysisOfVarianceDialogWrapper::GetChildWindowId();
936                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
937                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
938 
939                 pScMod->SetRefDialog( nId, pWnd == nullptr );
940             }
941             break;
942         case SID_CORRELATION_DIALOG:
943             {
944                 sal_uInt16 nId  = ScCorrelationDialogWrapper::GetChildWindowId();
945                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
946                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
947 
948                 pScMod->SetRefDialog( nId, pWnd == nullptr );
949             }
950             break;
951         case SID_COVARIANCE_DIALOG:
952             {
953                 sal_uInt16 nId  = ScCovarianceDialogWrapper::GetChildWindowId();
954                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
955                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
956 
957                 pScMod->SetRefDialog( nId, pWnd == nullptr );
958             }
959             break;
960         case SID_EXPONENTIAL_SMOOTHING_DIALOG:
961             {
962                 sal_uInt16 nId  = ScExponentialSmoothingDialogWrapper::GetChildWindowId();
963                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
964                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
965 
966                 pScMod->SetRefDialog( nId, pWnd == nullptr );
967             }
968             break;
969         case SID_MOVING_AVERAGE_DIALOG:
970             {
971                 sal_uInt16 nId  = ScMovingAverageDialogWrapper::GetChildWindowId();
972                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
973                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
974 
975                 pScMod->SetRefDialog( nId, pWnd == nullptr );
976             }
977             break;
978         case SID_REGRESSION_DIALOG:
979             {
980                 sal_uInt16 nId  = ScRegressionDialogWrapper::GetChildWindowId();
981                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
982                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
983 
984                 pScMod->SetRefDialog( nId, pWnd == nullptr );
985             }
986             break;
987         case SID_TTEST_DIALOG:
988             {
989                 sal_uInt16 nId  = ScTTestDialogWrapper::GetChildWindowId();
990                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
991                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
992 
993                 pScMod->SetRefDialog( nId, pWnd == nullptr );
994 
995             }
996             break;
997         case SID_FTEST_DIALOG:
998             {
999                 sal_uInt16 nId  = ScFTestDialogWrapper::GetChildWindowId();
1000                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1001                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1002 
1003                 pScMod->SetRefDialog( nId, pWnd == nullptr );
1004 
1005             }
1006             break;
1007         case SID_ZTEST_DIALOG:
1008             {
1009                 sal_uInt16 nId  = ScZTestDialogWrapper::GetChildWindowId();
1010                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1011                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1012 
1013                 pScMod->SetRefDialog( nId, pWnd == nullptr );
1014 
1015             }
1016             break;
1017         case SID_CHI_SQUARE_TEST_DIALOG:
1018             {
1019                 sal_uInt16 nId  = ScChiSquareTestDialogWrapper::GetChildWindowId();
1020                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1021                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1022 
1023                 pScMod->SetRefDialog( nId, pWnd == nullptr );
1024 
1025             }
1026             break;
1027         case SID_FOURIER_ANALYSIS_DIALOG:
1028             {
1029                 sal_uInt16 nId  = ScFourierAnalysisDialogWrapper::GetChildWindowId();
1030                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1031                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1032 
1033                 pScMod->SetRefDialog( nId, pWnd == nullptr );
1034 
1035             }
1036             break;
1037         case SID_SEARCH_RESULTS_DIALOG:
1038         {
1039             const SfxPoolItem* pItem = nullptr;
1040             if (pReqArgs && pReqArgs->HasItem(SID_SEARCH_RESULTS_DIALOG, &pItem))
1041             {
1042                 bool bVisible = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1043                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1044                 // The window ID should equal the slot ID, but not a biggie if it wasn't.
1045                 sal_uInt16 nId = sc::SearchResultsDlgWrapper::GetChildWindowId();
1046                 pViewFrm->SetChildWindow(nId, bVisible, false);
1047             }
1048             rReq.Done();
1049         }
1050         break;
1051 
1052         //  disposal (Outlines)
1053         //  SID_AUTO_OUTLINE, SID_OUTLINE_DELETEALL in Execute (in docsh.idl)
1054 
1055         case SID_OUTLINE_HIDE:
1056             if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1057                                     GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1058                 pTabViewShell->SetDataPilotDetails( false );
1059             else
1060                 pTabViewShell->HideMarkedOutlines();
1061             rReq.Done();
1062             break;
1063 
1064         case SID_OUTLINE_SHOW:
1065             {
1066                 ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1067                                     GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
1068                 if ( pDPObj )
1069                 {
1070                     Sequence<sheet::DataPilotFieldFilter> aFilters;
1071                     css::sheet::DataPilotFieldOrientation nOrientation;
1072                     if ( pTabViewShell->HasSelectionForDrillDown( nOrientation ) )
1073                     {
1074                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1075                         ScopedVclPtr<AbstractScDPShowDetailDlg> pDlg( pFact->CreateScDPShowDetailDlg(
1076                             pTabViewShell->GetFrameWeld(), *pDPObj, nOrientation ) );
1077                         if ( pDlg->Execute() == RET_OK )
1078                         {
1079                             OUString aNewDimName( pDlg->GetDimensionName() );
1080                             pTabViewShell->SetDataPilotDetails( true, &aNewDimName );
1081                         }
1082                     }
1083                     else if ( !pDPObj->IsServiceData() &&
1084                                pDPObj->GetDataFieldPositionData(
1085                                    ScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ),
1086                                    aFilters ) )
1087                         pTabViewShell->ShowDataPilotSourceData( *pDPObj, aFilters );
1088                     else
1089                         pTabViewShell->SetDataPilotDetails(true);
1090                 }
1091                 else
1092                     pTabViewShell->ShowMarkedOutlines();
1093                 rReq.Done();
1094             }
1095             break;
1096 
1097         case SID_OUTLINE_MAKE:
1098             {
1099                 bool bColumns = false;
1100                 bool bOk = true;
1101 
1102                 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1103                                         GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1104                 {
1105                     ScDPNumGroupInfo aNumInfo;
1106                     aNumInfo.mbEnable    = true;
1107                     aNumInfo.mbAutoStart = true;
1108                     aNumInfo.mbAutoEnd   = true;
1109                     sal_Int32 nParts = 0;
1110                     if ( pTabViewShell->HasSelectionForDateGroup( aNumInfo, nParts ) )
1111                     {
1112                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1113                         const Date& rNullDate( GetViewData()->GetDocument()->GetFormatTable()->GetNullDate() );
1114                         ScopedVclPtr<AbstractScDPDateGroupDlg> pDlg( pFact->CreateScDPDateGroupDlg(
1115                             pTabViewShell->GetFrameWeld(),
1116                             aNumInfo, nParts, rNullDate ) );
1117                         if( pDlg->Execute() == RET_OK )
1118                         {
1119                             aNumInfo = pDlg->GetGroupInfo();
1120                             pTabViewShell->DateGroupDataPilot( aNumInfo, pDlg->GetDatePart() );
1121                         }
1122                     }
1123                     else if ( pTabViewShell->HasSelectionForNumGroup( aNumInfo ) )
1124                     {
1125                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1126                         ScopedVclPtr<AbstractScDPNumGroupDlg> pDlg( pFact->CreateScDPNumGroupDlg(
1127                             pTabViewShell->GetFrameWeld(), aNumInfo ) );
1128                         if( pDlg->Execute() == RET_OK )
1129                             pTabViewShell->NumGroupDataPilot( pDlg->GetGroupInfo() );
1130                     }
1131                     else
1132                         pTabViewShell->GroupDataPilot();
1133 
1134                     bOk = false;
1135                 }
1136                 else if( pReqArgs != nullptr )
1137                 {
1138                     const SfxPoolItem* pItem;
1139                     bOk = false;
1140 
1141                     if( pReqArgs->HasItem( SID_OUTLINE_MAKE, &pItem ) )
1142                     {
1143                         OUString aCol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1144                         aCol = aCol.toAsciiUpperCase();
1145 
1146                         switch( aCol[0] )
1147                         {
1148                             case 'R': bColumns=false; bOk = true;break;
1149                             case 'C': bColumns=true; bOk = true;break;
1150                         }
1151                     }
1152                 }
1153                 else            // Dialog, when not whole rows/columns are marked
1154                 {
1155                     if ( GetViewData()->SimpleColMarked() && !GetViewData()->SimpleRowMarked() )
1156                         bColumns = true;
1157                     else if ( !GetViewData()->SimpleColMarked() && GetViewData()->SimpleRowMarked() )
1158                         bColumns = false;
1159                     else
1160                     {
1161                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1162 
1163                         ScopedVclPtr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetFrameWeld()));
1164                         if ( pDlg->Execute() == RET_OK )
1165                             bColumns = pDlg->GetColsChecked();
1166                         else
1167                             bOk = false;
1168                     }
1169                 }
1170                 if (bOk)
1171                 {
1172                     pTabViewShell->MakeOutline( bColumns );
1173 
1174                     if( ! rReq.IsAPI() )
1175                     {
1176                         OUString aCol = bColumns ? OUString('C') : OUString('R');
1177                         rReq.AppendItem( SfxStringItem( SID_OUTLINE_MAKE, aCol ) );
1178                         rReq.Done();
1179                     }
1180                 }
1181             }
1182             break;
1183 
1184         case SID_OUTLINE_REMOVE:
1185             {
1186                 bool bColumns = false;
1187                 bool bOk = true;
1188 
1189                 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1190                                         GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1191                 {
1192                     pTabViewShell->UngroupDataPilot();
1193                     bOk = false;
1194                 }
1195                 else if( pReqArgs != nullptr )
1196                 {
1197                     const SfxPoolItem* pItem;
1198                     bOk = false;
1199 
1200                     if( pReqArgs->HasItem( SID_OUTLINE_REMOVE, &pItem ) )
1201                     {
1202                         OUString aCol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1203                         aCol = aCol.toAsciiUpperCase();
1204 
1205                         switch (aCol[0])
1206                         {
1207                             case 'R': bColumns=false; bOk = true;break;
1208                             case 'C': bColumns=true; bOk = true;break;
1209                         }
1210                     }
1211                 }
1212                 else            // Dialog only when removal for rows and columns is possible
1213                 {
1214                     bool bColPoss, bRowPoss;
1215                     pTabViewShell->TestRemoveOutline( bColPoss, bRowPoss );
1216                     // TODO: handle this case in LOK too
1217                     if ( bColPoss && bRowPoss && !comphelper::LibreOfficeKit::isActive() )
1218                     {
1219                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1220 
1221                         ScopedVclPtr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetFrameWeld(), true));
1222                         if ( pDlg->Execute() == RET_OK )
1223                             bColumns = pDlg->GetColsChecked();
1224                         else
1225                             bOk = false;
1226                     }
1227                     else if ( bColPoss )
1228                         bColumns = true;
1229                     else if ( bRowPoss )
1230                         bColumns = false;
1231                     else
1232                         bOk = false;
1233                 }
1234                 if (bOk)
1235                 {
1236                     pTabViewShell->RemoveOutline( bColumns );
1237 
1238                     if( ! rReq.IsAPI() )
1239                     {
1240                         OUString aCol = bColumns ? OUString('C') : OUString('R');
1241                         rReq.AppendItem( SfxStringItem( SID_OUTLINE_REMOVE, aCol ) );
1242                         rReq.Done();
1243                     }
1244                 }
1245             }
1246             break;
1247 
1248         //  Clipboard
1249 
1250         case SID_COPY:              // for graphs in DrawShell
1251             {
1252                 weld::WaitObject aWait( GetViewData()->GetDialogParent() );
1253                 pTabViewShell->CopyToClip( nullptr, false, false, true );
1254                 rReq.Done();
1255                 GetViewData()->SetPasteMode( ScPasteFlags::Mode | ScPasteFlags::Border );
1256                 pTabViewShell->ShowCursor();
1257                 pTabViewShell->UpdateCopySourceOverlay();
1258             }
1259             break;
1260 
1261         case SID_CUT:               // for graphs in DrawShell
1262             {
1263                 weld::WaitObject aWait( GetViewData()->GetDialogParent() );
1264                 pTabViewShell->CutToClip();
1265                 rReq.Done();
1266                 GetViewData()->SetPasteMode( ScPasteFlags::Mode | ScPasteFlags::Border );
1267                 pTabViewShell->ShowCursor();
1268                 pTabViewShell->UpdateCopySourceOverlay();
1269             }
1270             break;
1271 
1272         case SID_PASTE:
1273             {
1274                 ScClipUtil::PasteFromClipboard ( GetViewData(), pTabViewShell, true );
1275                 rReq.Done();
1276             }
1277             break;
1278 
1279         case SID_CLIPBOARD_FORMAT_ITEMS:
1280             {
1281                 weld::WaitObject aWait( GetViewData()->GetDialogParent() );
1282 
1283                 SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
1284                 const SfxPoolItem* pItem;
1285                 if ( pReqArgs &&
1286                      pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET &&
1287                      dynamic_cast<const SfxUInt32Item*>( pItem) !=  nullptr )
1288                 {
1289                     nFormat = static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pItem)->GetValue());
1290                 }
1291 
1292                 if ( nFormat != SotClipboardFormatId::NONE )
1293                 {
1294                     css::uno::Reference<css::datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(GetViewData()->GetActiveWin()));
1295                     bool bCells = ( ScTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1296                     bool bDraw = ( ScDrawTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1297                     bool bOle = ( nFormat == SotClipboardFormatId::EMBED_SOURCE );
1298 
1299                     if ( bCells && bOle )
1300                         pTabViewShell->PasteFromSystem();
1301                     else if ( bDraw && bOle )
1302                         pTabViewShell->PasteDraw();
1303                     else
1304                         pTabViewShell->PasteFromSystem(nFormat);
1305                 }
1306                 //?else
1307                 //? pTabViewShell->PasteFromSystem();
1308 
1309                 rReq.Done();
1310             }
1311             pTabViewShell->CellContentChanged();
1312             break;
1313 
1314         case FID_INS_CELL_CONTENTS:
1315             {
1316                 InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
1317                 ScPasteFunc nFunction = ScPasteFunc::NONE;
1318                 InsCellCmd eMoveMode = INS_NONE;
1319 
1320                 ScDocument* pDoc = GetViewData()->GetDocument();
1321                 bool bOtherDoc = !pDoc->IsClipboardSource();
1322                 // keep a reference in case the clipboard is changed during dialog or PasteFromClip
1323                 const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(GetViewData()->GetActiveWin()));
1324                 if ( pOwnClip )
1325                 {
1326                     bool bSkipEmpty = false;
1327                     bool bTranspose = false;
1328                     bool bAsLink    = false;
1329 
1330                     if ( pReqArgs!=nullptr && pTabViewShell->SelectionEditable() )
1331                     {
1332                         const   SfxPoolItem* pItem;
1333                         OUString aFlags('A');
1334 
1335                         if( pReqArgs->HasItem( FID_INS_CELL_CONTENTS, &pItem ) )
1336                             aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
1337 
1338                         nFlags |= FlagsFromString(aFlags);
1339 
1340                         const SfxUInt16Item* pFuncItem = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
1341                         const SfxBoolItem* pSkipItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_2);
1342                         const SfxBoolItem* pTransposeItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_3);
1343                         const SfxBoolItem* pLinkItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_4);
1344                         const SfxInt16Item* pMoveItem = rReq.GetArg<SfxInt16Item>(FN_PARAM_5);
1345                         if ( pFuncItem )
1346                             nFunction = static_cast<ScPasteFunc>(pFuncItem->GetValue());
1347                         if ( pSkipItem )
1348                             bSkipEmpty = pSkipItem->GetValue();
1349                         if ( pTransposeItem )
1350                             bTranspose = pTransposeItem->GetValue();
1351                         if ( pLinkItem )
1352                             bAsLink = pLinkItem->GetValue();
1353                         if ( pMoveItem )
1354                             eMoveMode = static_cast<InsCellCmd>(pMoveItem->GetValue());
1355                     }
1356                     else
1357                     {
1358                         ScEditableTester aTester( pTabViewShell );
1359                         if (aTester.IsEditable())
1360                         {
1361                             ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1362 
1363                             ScopedVclPtr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg(pTabViewShell->GetFrameWeld()));
1364                             pDlg->SetOtherDoc( bOtherDoc );
1365                             // if ChangeTrack MoveMode disable
1366                             pDlg->SetChangeTrack( pDoc->GetChangeTrack() != nullptr );
1367                             // fdo#56098  disable shift if necessary
1368                             if (!bOtherDoc)
1369                             {
1370                                 ScViewData* pData = GetViewData();
1371                                 if ( pData->GetMarkData().GetTableSelect( pData->GetTabNo() ) )
1372                                 {
1373                                     SCCOL nStartX, nEndX, nClipStartX, nClipSizeX, nRangeSizeX;
1374                                     SCROW nStartY, nEndY, nClipStartY, nClipSizeY, nRangeSizeY;
1375                                     SCTAB nStartTab, nEndTab;
1376                                     pOwnClip->GetDocument()->GetClipStart( nClipStartX, nClipStartY );
1377                                     pOwnClip->GetDocument()->GetClipArea( nClipSizeX, nClipSizeY, true );
1378 
1379                                     if ( !( pData->GetSimpleArea( nStartX, nStartY, nStartTab,
1380                                                    nEndX, nEndY, nEndTab ) == SC_MARK_SIMPLE &&
1381                                                    nStartTab == nEndTab ) )
1382                                     {
1383                                         // the destination is not a simple range,
1384                                         // assume the destination as the current cell
1385                                         nStartX = nEndX = pData->GetCurX();
1386                                         nStartY = nEndY = pData->GetCurY();
1387                                         nStartTab = pData->GetTabNo();
1388                                     }
1389                                     // we now have clip- and range dimensions
1390                                     // the size of the destination area is the larger of the two
1391                                     nRangeSizeX = nClipSizeX >= nEndX - nStartX ? nClipSizeX : nEndX - nStartX;
1392                                     nRangeSizeY = nClipSizeY >= nEndY - nStartY ? nClipSizeY : nEndY - nStartY;
1393                                     // When the source and destination areas intersect things may go wrong,
1394                                     // especially if the area contains references. This may produce data loss
1395                                     // (e.g. formulas that get wrong references), this scenario _must_ be avoided.
1396                                     ScRange aSource( nClipStartX, nClipStartY, nStartTab,
1397                                                      nClipStartX + nClipSizeX, nClipStartY + nClipSizeY, nStartTab );
1398                                     ScRange aDest( nStartX, nStartY, nStartTab,
1399                                                    nStartX + nRangeSizeX, nStartY + nRangeSizeY, nStartTab );
1400                                     if ( pOwnClip->GetDocument()->IsCutMode() && aSource.Intersects( aDest ) )
1401                                         pDlg->SetCellShiftDisabled( CellShiftDisabledFlags::Down | CellShiftDisabledFlags::Right );
1402                                     else
1403                                     {
1404                                         //no conflict with intersecting ranges,
1405                                         //check if paste plus shift will fit on sheet
1406                                         //and disable shift-option if no fit
1407                                         CellShiftDisabledFlags nDisableShiftX = CellShiftDisabledFlags::NONE;
1408                                         CellShiftDisabledFlags nDisableShiftY = CellShiftDisabledFlags::NONE;
1409 
1410                                         //check if horizontal shift will fit
1411                                         if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1412                                                     pDoc->MaxCol() - nRangeSizeX, nStartY,
1413                                                     pDoc->MaxCol(), nStartY + nRangeSizeY ) )
1414                                             nDisableShiftX = CellShiftDisabledFlags::Right;
1415 
1416                                         //check if vertical shift will fit
1417                                         if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1418                                                     nStartX, pDoc->MaxRow() - nRangeSizeY,
1419                                                     nStartX + nRangeSizeX, pDoc->MaxRow() ) )
1420                                             nDisableShiftY = CellShiftDisabledFlags::Down;
1421 
1422                                         if ( nDisableShiftX != CellShiftDisabledFlags::NONE || nDisableShiftY != CellShiftDisabledFlags::NONE)
1423                                             pDlg->SetCellShiftDisabled( nDisableShiftX | nDisableShiftY );
1424                                     }
1425                                 }
1426                             }
1427                             if (pDlg->Execute() == RET_OK)
1428                             {
1429                                 nFlags     = pDlg->GetInsContentsCmdBits();
1430                                 nFunction  = pDlg->GetFormulaCmdBits();
1431                                 bSkipEmpty = pDlg->IsSkipEmptyCells();
1432                                 bTranspose = pDlg->IsTranspose();
1433                                 bAsLink    = pDlg->IsLink();
1434                                 eMoveMode  = pDlg->GetMoveMode();
1435                             }
1436                         }
1437                         else
1438                             pTabViewShell->ErrorMessage(aTester.GetMessageId());
1439                     }
1440 
1441                     if( nFlags != InsertDeleteFlags::NONE )
1442                     {
1443                         {
1444                             weld::WaitObject aWait( GetViewData()->GetDialogParent() );
1445                             if ( bAsLink && bOtherDoc )
1446                                 pTabViewShell->PasteFromSystem(SotClipboardFormatId::LINK);  // DDE insert
1447                             else
1448                             {
1449                                 pTabViewShell->PasteFromClip( nFlags, pOwnClip->GetDocument(),
1450                                     nFunction, bSkipEmpty, bTranspose, bAsLink,
1451                                     eMoveMode, InsertDeleteFlags::NONE, true );    // allow warning dialog
1452                             }
1453                         }
1454 
1455                         if( !pReqArgs )
1456                         {
1457                             OUString  aFlags = FlagsToString( nFlags );
1458 
1459                             rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1460                             rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bSkipEmpty ) );
1461                             rReq.AppendItem( SfxBoolItem( FN_PARAM_3, bTranspose ) );
1462                             rReq.AppendItem( SfxBoolItem( FN_PARAM_4, bAsLink ) );
1463                             rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nFunction) ) );
1464                             rReq.AppendItem( SfxInt16Item( FN_PARAM_5, static_cast<sal_Int16>(eMoveMode) ) );
1465                             rReq.Done();
1466                         }
1467                     }
1468                 }
1469             }
1470             pTabViewShell->CellContentChanged();        // => PasteFromXXX ???
1471             break;
1472         case SID_PASTE_ONLY_VALUE:
1473         case SID_PASTE_ONLY_TEXT:
1474         case SID_PASTE_ONLY_FORMULA:
1475         {
1476             if ( ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(GetViewData()->GetActiveWin())) )  // own cell data
1477             {
1478                 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1479                 OUString aFlags;
1480                 if ( nSlot == SID_PASTE_ONLY_VALUE )
1481                     aFlags = "V";
1482                 else if ( nSlot == SID_PASTE_ONLY_TEXT )
1483                     aFlags = "S";
1484                 else
1485                     aFlags = "F";
1486                 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1487                 ExecuteSlot( rReq, GetInterface() );
1488                 rReq.SetReturnValue(SfxInt16Item(nSlot, 1));    // 1 = success
1489                 pTabViewShell->CellContentChanged();
1490             }
1491             else
1492                 rReq.SetReturnValue(SfxInt16Item(nSlot, 0));        // 0 = fail
1493             break;
1494         }
1495         case SID_PASTE_SPECIAL:
1496             // differentiate between own cell data and draw objects/external data
1497             // this makes FID_INS_CELL_CONTENTS superfluous
1498             {
1499                 vcl::Window* pWin = GetViewData()->GetActiveWin();
1500                 css::uno::Reference<css::datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(pWin));
1501 
1502                 //  Clipboard-ID given as parameter? Basic "PasteSpecial(Format)"
1503                 const SfxPoolItem* pItem=nullptr;
1504                 if ( pReqArgs &&
1505                      pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET &&
1506                      dynamic_cast<const SfxUInt32Item*>( pItem) !=  nullptr )
1507                 {
1508                     SotClipboardFormatId nFormat = static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pItem)->GetValue());
1509                     bool bRet=true;
1510                     {
1511                         weld::WaitObject aWait( GetViewData()->GetDialogParent() );
1512                         bool bDraw = ( ScDrawTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1513                         if ( bDraw && nFormat == SotClipboardFormatId::EMBED_SOURCE )
1514                             pTabViewShell->PasteDraw();
1515                         else
1516                             bRet = pTabViewShell->PasteFromSystem(nFormat, true);       // TRUE: no error messages
1517                     }
1518 
1519                     if ( bRet )
1520                     {
1521                         rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success, 0 = fail
1522                         rReq.Done();
1523                     }
1524                     else
1525                         // if format is not available -> fallback to request without parameters
1526                         pItem = nullptr;
1527                 }
1528 
1529                 if ( !pItem )
1530                 {
1531                     if ( ScTransferObj::GetOwnClipboard(xTransferable) )  // own cell data
1532                     {
1533                         rReq.SetSlot( FID_INS_CELL_CONTENTS );
1534                         ExecuteSlot( rReq, GetInterface() );
1535                         rReq.SetReturnValue(SfxInt16Item(nSlot, 1));    // 1 = success
1536                     }
1537                     else                                    // draw objects or external data
1538                     {
1539                         bool bDraw = ( ScDrawTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1540 
1541                         SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1542                         GetPossibleClipboardFormats( aFormats );
1543 
1544                         sal_uInt16 nFormatCount = aFormats.Count();
1545                         if ( nFormatCount )
1546                         {
1547                             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1548                             ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(pTabViewShell->GetFrameWeld()));
1549                             for (sal_uInt16 i=0; i<nFormatCount; i++)
1550                             {
1551                                 SotClipboardFormatId nFormatId = aFormats.GetClipbrdFormatId( i );
1552                                 OUString aName = aFormats.GetClipbrdFormatName( i );
1553                                 // special case for paste dialog: '*' is replaced by object type
1554                                 if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE )
1555                                     aName = "*";
1556                                 pDlg->Insert( nFormatId, aName );
1557                             }
1558 
1559                             TransferableDataHelper aDataHelper(
1560                                 TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
1561                             SotClipboardFormatId nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
1562                             if (nFormat != SotClipboardFormatId::NONE)
1563                             {
1564                                 {
1565                                     weld::WaitObject aWait( GetViewData()->GetDialogParent() );
1566                                     if ( bDraw && nFormat == SotClipboardFormatId::EMBED_SOURCE )
1567                                         pTabViewShell->PasteDraw();
1568                                     else
1569                                         pTabViewShell->PasteFromSystem(nFormat);
1570                                 }
1571                                 rReq.SetReturnValue(SfxInt16Item(nSlot, 1));    // 1 = success
1572                                 rReq.AppendItem( SfxUInt32Item( nSlot, static_cast<sal_uInt32>(nFormat) ) );
1573                                 rReq.Done();
1574                             }
1575                             else
1576                             {
1577                                 rReq.SetReturnValue(SfxInt16Item(nSlot, 0));    // 0 = fail
1578                                 rReq.Ignore();
1579                             }
1580                         }
1581                         else
1582                             rReq.SetReturnValue(SfxInt16Item(nSlot, 0));        // 0 = fail
1583                     }
1584                 }
1585             }
1586             pTabViewShell->CellContentChanged();        // => PasteFromSystem() ???
1587             break;
1588 
1589         case SID_PASTE_UNFORMATTED:
1590             // differentiate between own cell data and draw objects/external data
1591             // this makes FID_INS_CELL_CONTENTS superfluous
1592             {
1593                 weld::WaitObject aWait( GetViewData()->GetDialogParent() );
1594 
1595                 // we should differentiate between SotClipboardFormatId::STRING and SotClipboardFormatId::STRING_TSVC,
1596                 // and paste the SotClipboardFormatId::STRING_TSVC if it is available.
1597                 // Which makes a difference if the clipboard contains cells with embedded line breaks.
1598 
1599                 SotClipboardFormatId nFormat = HasClipboardFormat( SotClipboardFormatId::STRING_TSVC) ?
1600                     SotClipboardFormatId::STRING_TSVC : SotClipboardFormatId::STRING;
1601 
1602                 const bool bRet = pTabViewShell->PasteFromSystem(nFormat, true); // TRUE: no error messages
1603                 if ( bRet )
1604                 {
1605                     rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1606                     rReq.Done();
1607                 }
1608                 else
1609                 {
1610                     rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1611                 }
1612 
1613                 pTabViewShell->CellContentChanged();        // => PasteFromSystem() ???
1614             }
1615             break;
1616 
1617         //  other
1618 
1619         case FID_INS_ROWBRK:
1620             pTabViewShell->InsertPageBreak( false );
1621             rReq.Done();
1622             break;
1623 
1624         case FID_INS_COLBRK:
1625             pTabViewShell->InsertPageBreak( true );
1626             rReq.Done();
1627             break;
1628 
1629         case FID_DEL_ROWBRK:
1630             pTabViewShell->DeletePageBreak( false );
1631             rReq.Done();
1632             break;
1633 
1634         case FID_DEL_COLBRK:
1635             pTabViewShell->DeletePageBreak( true );
1636             rReq.Done();
1637             break;
1638 
1639         case SID_DETECTIVE_ADD_PRED:
1640             pTabViewShell->DetectiveAddPred();
1641             rReq.Done();
1642             break;
1643 
1644         case SID_DETECTIVE_DEL_PRED:
1645             pTabViewShell->DetectiveDelPred();
1646             rReq.Done();
1647             break;
1648 
1649         case SID_DETECTIVE_ADD_SUCC:
1650             pTabViewShell->DetectiveAddSucc();
1651             rReq.Done();
1652             break;
1653 
1654         case SID_DETECTIVE_DEL_SUCC:
1655             pTabViewShell->DetectiveDelSucc();
1656             rReq.Done();
1657             break;
1658 
1659         case SID_DETECTIVE_ADD_ERR:
1660             pTabViewShell->DetectiveAddError();
1661             rReq.Done();
1662             break;
1663 
1664         case SID_DETECTIVE_INVALID:
1665             pTabViewShell->DetectiveMarkInvalid();
1666             rReq.Done();
1667             break;
1668 
1669         case SID_DETECTIVE_REFRESH:
1670             pTabViewShell->DetectiveRefresh();
1671             rReq.Done();
1672             break;
1673 
1674         case SID_DETECTIVE_MARK_PRED:
1675             pTabViewShell->DetectiveMarkPred();
1676             break;
1677         case SID_DETECTIVE_MARK_SUCC:
1678             pTabViewShell->DetectiveMarkSucc();
1679             break;
1680         case SID_INSERT_CURRENT_DATE:
1681             pTabViewShell->InsertCurrentTime(
1682                 SvNumFormatType::DATE, ScResId(STR_UNDO_INSERT_CURRENT_DATE));
1683             break;
1684         case SID_INSERT_CURRENT_TIME:
1685             pTabViewShell->InsertCurrentTime(
1686                 SvNumFormatType::TIME, ScResId(STR_UNDO_INSERT_CURRENT_TIME));
1687             break;
1688 
1689         case SID_SPELL_DIALOG:
1690             {
1691                 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
1692                 if( rReq.GetArgs() )
1693                     pViewFrame->SetChildWindow( SID_SPELL_DIALOG,
1694                         static_cast< const SfxBoolItem& >( rReq.GetArgs()->
1695                             Get( SID_SPELL_DIALOG ) ).GetValue() );
1696                 else
1697                     pViewFrame->ToggleChildWindow( SID_SPELL_DIALOG );
1698 
1699                 pViewFrame->GetBindings().Invalidate( SID_SPELL_DIALOG );
1700                 rReq.Ignore();
1701             }
1702             break;
1703 
1704         case SID_HANGUL_HANJA_CONVERSION:
1705             pTabViewShell->DoHangulHanjaConversion();
1706             break;
1707 
1708         case SID_CHINESE_CONVERSION:
1709             {
1710                 //open ChineseTranslationDialog
1711                 Reference< XComponentContext > xContext(
1712                     ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1713                 if(xContext.is())
1714                 {
1715                     Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1716                     if(xMCF.is())
1717                     {
1718                         Reference< ui::dialogs::XExecutableDialog > xDialog(
1719                                 xMCF->createInstanceWithContext(
1720                                     "com.sun.star.linguistic2.ChineseTranslationDialog"
1721                                     , xContext),
1722                                 UNO_QUERY);
1723                         Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1724                         if( xInit.is() )
1725                         {
1726                             //  initialize dialog
1727                             uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
1728                             {
1729                                 {"ParentWindow", uno::Any(Reference< awt::XWindow >())}
1730                             }));
1731                             xInit->initialize( aSeq );
1732 
1733                             //execute dialog
1734                             sal_Int16 nDialogRet = xDialog->execute();
1735                             if( RET_OK == nDialogRet )
1736                             {
1737                                 //get some parameters from the dialog
1738                                 bool bToSimplified = true;
1739                                 bool bUseVariants = true;
1740                                 bool bCommonTerms = true;
1741                                 Reference< beans::XPropertySet >  xProp( xDialog, UNO_QUERY );
1742                                 if( xProp.is() )
1743                                 {
1744                                     try
1745                                     {
1746                                         xProp->getPropertyValue("IsDirectionToSimplified") >>= bToSimplified;
1747                                         xProp->getPropertyValue("IsUseCharacterVariants") >>= bUseVariants;
1748                                         xProp->getPropertyValue("IsTranslateCommonTerms") >>= bCommonTerms;
1749                                     }
1750                                     catch( Exception& )
1751                                     {
1752                                     }
1753                                 }
1754 
1755                                 //execute translation
1756                                 LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1757                                 LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1758                                 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1759                                 if( !bCommonTerms )
1760                                     nOptions |= i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1761 
1762                                 vcl::Font aTargetFont = OutputDevice::GetDefaultFont(
1763                                                     DefaultFontType::CJK_SPREADSHEET,
1764                                                     eTargetLang, GetDefaultFontFlags::OnlyOne );
1765                                 ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
1766                                     eSourceLang, eTargetLang, aTargetFont, nOptions, false );
1767                                 pTabViewShell->DoSheetConversion( aConvParam );
1768                             }
1769                         }
1770                         Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1771                         if( xComponent.is() )
1772                             xComponent->dispose();
1773                     }
1774                 }
1775             }
1776             break;
1777 
1778         case SID_CONVERT_FORMULA_TO_VALUE:
1779         {
1780             pTabViewShell->ConvertFormulaToValue();
1781         }
1782         break;
1783         case SID_THESAURUS:
1784             pTabViewShell->DoThesaurus();
1785             break;
1786 
1787         case SID_TOGGLE_REL:
1788             pTabViewShell->DoRefConversion();
1789             break;
1790 
1791         case SID_DEC_INDENT:
1792             pTabViewShell->ChangeIndent( false );
1793             break;
1794         case SID_INC_INDENT:
1795             pTabViewShell->ChangeIndent( true );
1796             break;
1797 
1798         case FID_USE_NAME:
1799             {
1800                 CreateNameFlags nFlags = pTabViewShell->GetCreateNameFlags();
1801 
1802                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1803 
1804                 ScopedVclPtr<AbstractScNameCreateDlg> pDlg(pFact->CreateScNameCreateDlg(pTabViewShell->GetFrameWeld(), nFlags));
1805 
1806                 if( pDlg->Execute() )
1807                 {
1808                     pTabViewShell->CreateNames(pDlg->GetFlags());
1809                     rReq.Done();
1810                 }
1811             }
1812             break;
1813 
1814         case SID_CONSOLIDATE:
1815             {
1816                 const SfxPoolItem* pItem;
1817                 if ( pReqArgs && SfxItemState::SET ==
1818                         pReqArgs->GetItemState( SCITEM_CONSOLIDATEDATA, true, &pItem ) )
1819                 {
1820                     const ScConsolidateParam& rParam =
1821                             static_cast<const ScConsolidateItem*>(pItem)->GetData();
1822 
1823                     pTabViewShell->Consolidate( rParam );
1824                     GetViewData()->GetDocument()->SetConsolidateDlgData( std::unique_ptr<ScConsolidateParam>(new ScConsolidateParam(rParam)) );
1825 
1826                     rReq.Done();
1827                 }
1828 #if HAVE_FEATURE_SCRIPTING
1829                 else if (rReq.IsAPI())
1830                     SbxBase::SetError(ERRCODE_BASIC_BAD_PARAMETER);
1831 #endif
1832             }
1833             break;
1834 
1835         case SID_INS_FUNCTION:
1836             {
1837                 const SfxBoolItem* pOkItem = static_cast<const SfxBoolItem*>(&pReqArgs->Get( SID_DLG_RETOK ));
1838 
1839                 if ( pOkItem->GetValue() )      // OK
1840                 {
1841                     OUString             aFormula;
1842                     const SfxStringItem* pSItem      = static_cast<const SfxStringItem*>(&pReqArgs->Get( SCITEM_STRING ));
1843                     const SfxBoolItem*   pMatrixItem = static_cast<const SfxBoolItem*>(&pReqArgs->Get( SID_DLG_MATRIX ));
1844 
1845                     aFormula += pSItem->GetValue();
1846                     pScMod->ActivateInputWindow( &aFormula, pMatrixItem->GetValue() );
1847                 }
1848                 else                            // CANCEL
1849                 {
1850                     pScMod->ActivateInputWindow();
1851                 }
1852                 rReq.Ignore();      // only SID_ENTER_STRING is recorded
1853             }
1854             break;
1855 
1856         case FID_DEFINE_NAME:
1857         case FID_DEFINE_CURRENT_NAME:
1858             if ( pReqArgs )
1859             {
1860                 const SfxPoolItem* pItem;
1861                 OUString  aName, aSymbol, aAttrib;
1862 
1863                 if( pReqArgs->HasItem( FID_DEFINE_NAME, &pItem ) )
1864                     aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
1865 
1866                 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
1867                     aSymbol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1868 
1869                 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
1870                     aAttrib = static_cast<const SfxStringItem*>(pItem)->GetValue();
1871 
1872                 if ( !aName.isEmpty() && !aSymbol.isEmpty() )
1873                 {
1874                     if (pTabViewShell->InsertName( aName, aSymbol, aAttrib ))
1875                         rReq.Done();
1876 #if HAVE_FEATURE_SCRIPTING
1877                     else
1878                         SbxBase::SetError( ERRCODE_BASIC_BAD_PARAMETER );  // Basic-error
1879 #endif
1880                 }
1881             }
1882             else
1883             {
1884                 sal_uInt16          nId  = ScNameDlgWrapper::GetChildWindowId();
1885                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1886                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1887 
1888                 pScMod->SetRefDialog( nId, pWnd == nullptr );
1889             }
1890             break;
1891         case FID_ADD_NAME:
1892             {
1893                 sal_uInt16          nId  = ScNameDefDlgWrapper::GetChildWindowId();
1894                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1895                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1896 
1897                 pScMod->SetRefDialog( nId, pWnd == nullptr );
1898             }
1899             break;
1900 
1901         case SID_OPENDLG_CONDFRMT:
1902         case SID_OPENDLG_CURRENTCONDFRMT:
1903         case SID_OPENDLG_COLORSCALE:
1904         case SID_OPENDLG_DATABAR:
1905         case SID_OPENDLG_ICONSET:
1906         case SID_OPENDLG_CONDDATE:
1907             {
1908                 sal_uInt32  nIndex      = sal_uInt32(-1);
1909                 bool        bManaged    = false;
1910 
1911                 // Get the pool item stored by Conditional Format Manager Dialog.
1912                 auto itemsRange = pTabViewShell->GetPool().GetItemSurrogates(SCITEM_CONDFORMATDLGDATA);
1913                 if (itemsRange.begin() != itemsRange.end())
1914                 {
1915                     const ScCondFormatDlgItem* pDlgItem = static_cast<const ScCondFormatDlgItem*>(*itemsRange.begin());
1916                     nIndex = pDlgItem->GetIndex();
1917                     bManaged = true;
1918                 }
1919 
1920                 // Check if the Conditional Manager Dialog is editing or adding
1921                 // conditional format item.
1922                 if ( bManaged )
1923                 {
1924                     sal_uInt16 nId = ScCondFormatDlgWrapper::GetChildWindowId();
1925                     SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1926                     SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1927 
1928                     pScMod->SetRefDialog( nId, pWnd == nullptr );
1929                     break;
1930                 }
1931 
1932                 ScRangeList aRangeList;
1933                 ScViewData* pData = GetViewData();
1934                 pData->GetMarkData().FillRangeListWithMarks(&aRangeList, false);
1935 
1936                 ScDocument* pDoc = GetViewData()->GetDocument();
1937                 if(pDoc->IsTabProtected(pData->GetTabNo()))
1938                 {
1939                     pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
1940                     break;
1941                 }
1942 
1943                 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
1944                 if(aRangeList.empty())
1945                 {
1946                     aRangeList.push_back(ScRange(aPos));
1947                 }
1948 
1949                 // try to find an existing conditional format
1950                 const ScConditionalFormat* pCondFormat = nullptr;
1951                 const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
1952                 ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
1953                 const ScCondFormatIndexes& rCondFormats = pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData();
1954                 bool bContainsCondFormat = !rCondFormats.empty();
1955                 bool bCondFormatDlg = false;
1956                 bool bContainsExistingCondFormat = false;
1957                 if(bContainsCondFormat)
1958                 {
1959                     for (const auto& rCondFormat : rCondFormats)
1960                     {
1961                         // check if at least one existing conditional format has the same range
1962                         pCondFormat = pList->GetFormat(rCondFormat);
1963                         if(!pCondFormat)
1964                             continue;
1965 
1966                         bContainsExistingCondFormat = true;
1967                         const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1968                         if(rCondFormatRange == aRangeList)
1969                         {
1970                             // found a matching range, edit this conditional format
1971                             bCondFormatDlg = true;
1972                             nIndex = pCondFormat->GetKey();
1973                             break;
1974                         }
1975                     }
1976                 }
1977 
1978                 // do we have a parameter with the conditional formatting type?
1979                 const SfxInt16Item* pParam = rReq.GetArg<SfxInt16Item>(FN_PARAM_1);
1980                 if (pParam && nSlot == SID_OPENDLG_ICONSET)
1981                 {
1982                     auto pFormat = std::make_unique<ScConditionalFormat>(0, pDoc);
1983                     pFormat->SetRange(aRangeList);
1984 
1985                     ScIconSetType eIconSetType = limit_cast<ScIconSetType>(pParam->GetValue(), IconSet_3Arrows, IconSet_5Boxes);
1986                     const int nSteps = ScIconSetFormat::getIconSetElements(eIconSetType);
1987 
1988                     ScIconSetFormat* pEntry = new ScIconSetFormat(pDoc);
1989                     ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData(eIconSetType);
1990 
1991                     pIconSetFormatData->m_Entries.push_back(std::make_unique<ScColorScaleEntry>(0, COL_RED, COLORSCALE_PERCENT));
1992                     pIconSetFormatData->m_Entries.push_back(std::make_unique<ScColorScaleEntry>(round(100. / nSteps), COL_BROWN, COLORSCALE_PERCENT));
1993                     pIconSetFormatData->m_Entries.push_back(std::make_unique<ScColorScaleEntry>(round(200. / nSteps), COL_YELLOW, COLORSCALE_PERCENT));
1994                     if (nSteps > 3)
1995                         pIconSetFormatData->m_Entries.push_back(std::make_unique<ScColorScaleEntry>(round(300. / nSteps), COL_WHITE, COLORSCALE_PERCENT));
1996                     if (nSteps > 4)
1997                         pIconSetFormatData->m_Entries.push_back(std::make_unique<ScColorScaleEntry>(round(400. / nSteps), COL_GREEN, COLORSCALE_PERCENT));
1998 
1999                     pEntry->SetIconSetData(pIconSetFormatData);
2000                     pFormat->AddEntry(pEntry);
2001 
2002                     // use the new conditional formatting
2003                     GetViewData()->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nIndex, std::move(pFormat), aPos.Tab(), aRangeList);
2004 
2005                     break;
2006                 }
2007 
2008                 // if not found a conditional format ask whether we should edit one of the existing
2009                 // or should create a new overlapping conditional format
2010                 if(bContainsCondFormat && !bCondFormatDlg && bContainsExistingCondFormat)
2011                 {
2012                     std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
2013                                                                    VclMessageType::Question, VclButtonsType::YesNo,
2014                                                                    ScResId(STR_EDIT_EXISTING_COND_FORMATS)));
2015                     xQueryBox->set_default_response(RET_YES);
2016                     bool bEditExisting = xQueryBox->run() == RET_YES;
2017                     if (bEditExisting)
2018                     {
2019                         // differentiate between ranges where one conditional format is defined
2020                         // and several formats are defined
2021                         // if we have only one => open the cond format dlg to edit it
2022                         // otherwise open the manage cond format dlg
2023                         if (rCondFormats.size() == 1)
2024                         {
2025                             pCondFormat = pList->GetFormat(rCondFormats[0]);
2026                             assert(pCondFormat);
2027                             bCondFormatDlg = true;
2028                         }
2029                         else
2030                         {
2031                             // Queue message to open Conditional Format Manager Dialog.
2032                             GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT_MANAGER, SfxCallMode::ASYNCHRON );
2033                             break;
2034                         }
2035                     }
2036                     else
2037                     {
2038                         // define an overlapping conditional format
2039                         // does not need to be handled here
2040                     }
2041                 }
2042 
2043                 condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
2044                 switch(nSlot)
2045                 {
2046                     case SID_OPENDLG_CONDFRMT:
2047                     case SID_OPENDLG_CURRENTCONDFRMT:
2048                         eType = condformat::dialog::CONDITION;
2049                         break;
2050                     case SID_OPENDLG_COLORSCALE:
2051                         eType = condformat::dialog::COLORSCALE;
2052                         break;
2053                     case SID_OPENDLG_DATABAR:
2054                         eType = condformat::dialog::DATABAR;
2055                         break;
2056                     case SID_OPENDLG_ICONSET:
2057                         eType = condformat::dialog::ICONSET;
2058                         break;
2059                     case SID_OPENDLG_CONDDATE:
2060                         eType = condformat::dialog::DATE;
2061                         break;
2062                     default:
2063                         assert(false);
2064                         break;
2065                 }
2066 
2067 
2068                 if(bCondFormatDlg || !bContainsCondFormat)
2069                 {
2070                     // Put the xml string parameter to initialize the
2071                     // Conditional Format Dialog.
2072                     ScCondFormatDlgItem aDlgItem(nullptr, nIndex, false);
2073                     aDlgItem.SetDialogType(eType);
2074                     pTabViewShell->GetPool().Put(aDlgItem);
2075 
2076                     sal_uInt16      nId      = ScCondFormatDlgWrapper::GetChildWindowId();
2077                     SfxViewFrame*   pViewFrm = pTabViewShell->GetViewFrame();
2078                     SfxChildWindow* pWnd     = pViewFrm->GetChildWindow( nId );
2079 
2080                     pScMod->SetRefDialog( nId, pWnd == nullptr );
2081                 }
2082             }
2083             break;
2084 
2085         case SID_DEFINE_COLROWNAMERANGES:
2086             {
2087 
2088                 sal_uInt16          nId  = ScColRowNameRangesDlgWrapper::GetChildWindowId();
2089                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2090                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2091 
2092                 pScMod->SetRefDialog( nId, pWnd == nullptr );
2093 
2094             }
2095             break;
2096 
2097         case SID_UPDATECHART:
2098             {
2099                 bool bAll = false;
2100 
2101                 if( pReqArgs )
2102                 {
2103                     const SfxPoolItem* pItem;
2104 
2105                     if( pReqArgs->HasItem( SID_UPDATECHART, &pItem ) )
2106                         bAll = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2107                 }
2108 
2109                 pTabViewShell->UpdateCharts( bAll );
2110 
2111                 if( ! rReq.IsAPI() )
2112                 {
2113                     rReq.AppendItem( SfxBoolItem( SID_UPDATECHART, bAll ) );
2114                     rReq.Done();
2115                 }
2116             }
2117             break;
2118 
2119         case SID_TABOP:
2120             if (pReqArgs)
2121             {
2122                 const ScTabOpItem& rItem =
2123                         static_cast<const ScTabOpItem&>(
2124                             pReqArgs->Get( SID_TABOP ));
2125 
2126                 pTabViewShell->TabOp( rItem.GetData() );
2127 
2128                 rReq.Done( *pReqArgs );
2129             }
2130             break;
2131 
2132         case SID_SOLVE:
2133             if (pReqArgs)
2134             {
2135                 const ScSolveItem& rItem =
2136                         static_cast<const ScSolveItem&>(
2137                             pReqArgs->Get( SCITEM_SOLVEDATA ));
2138 
2139                 pTabViewShell->Solve( rItem.GetData() );
2140 
2141                 rReq.Done( *pReqArgs );
2142             }
2143             break;
2144 
2145         case FID_INSERT_NAME:
2146             {
2147                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2148 
2149                 ScopedVclPtr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg(pTabViewShell->GetFrameWeld(), GetViewData()->GetDocShell()));
2150                 switch( pDlg->Execute() )
2151                 {
2152                     case BTN_PASTE_LIST:
2153                         pTabViewShell->InsertNameList();
2154                         break;
2155                     case BTN_PASTE_NAME:
2156                         {
2157                             ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
2158                             if (pHdl)
2159                             {
2160                                 //  "=" in KeyEvent, switches to input-mode
2161                                 (void)pScMod->InputKeyEvent( KeyEvent('=', vcl::KeyCode()) );
2162 
2163                                 std::vector<OUString> aNames = pDlg->GetSelectedNames();
2164                                 if (!aNames.empty())
2165                                 {
2166                                     OUStringBuffer aBuffer;
2167                                     for (const auto& rName : aNames)
2168                                     {
2169                                         aBuffer.append(rName).append(' ');
2170                                     }
2171                                     pHdl->InsertFunction( aBuffer.makeStringAndClear(), false );       // without "()"
2172                                 }
2173                             }
2174                         }
2175                         break;
2176                 }
2177             }
2178             break;
2179 
2180         case SID_RANGE_NOTETEXT:
2181             if (pReqArgs)
2182             {
2183                 const SfxStringItem& rTextItem = static_cast<const SfxStringItem&>(pReqArgs->Get( SID_RANGE_NOTETEXT ));
2184 
2185                 //  always cursor position
2186                 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2187                 pTabViewShell->SetNoteText( aPos, rTextItem.GetValue() );
2188                 rReq.Done();
2189             }
2190             break;
2191 
2192         case SID_INSERT_POSTIT:
2193         case SID_EDIT_POSTIT:
2194             {
2195                 const SfxPoolItem* pText;
2196                 if ( pReqArgs && pReqArgs->HasItem( SID_ATTR_POSTIT_TEXT, &pText) )
2197                 {
2198                     const SfxPoolItem* pCellId;
2199                     OUString aCellId;
2200                     // SID_ATTR_POSTIT_ID only argument for SID_EDIT_POSTIT
2201                     if (pReqArgs->HasItem( SID_ATTR_POSTIT_ID, &pCellId ))
2202                         aCellId = static_cast<const SvxPostItIdItem*>(pCellId)->GetValue();
2203 
2204                     const SvxPostItTextItem*    pTextItem   = static_cast<const SvxPostItTextItem*>( pText );
2205                     const SvxPostItAuthorItem*  pAuthorItem = pReqArgs->GetItem( SID_ATTR_POSTIT_AUTHOR );
2206                     const SvxPostItDateItem*    pDateItem   = pReqArgs->GetItem( SID_ATTR_POSTIT_DATE );
2207 
2208                     if (!aCellId.isEmpty())
2209                     {
2210                         SetTabNoAndCursor( GetViewData(), aCellId );
2211                     }
2212 
2213                     ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2214                     pTabViewShell->ReplaceNote( aPos, pTextItem->GetValue(),
2215                                                 pAuthorItem ? &pAuthorItem->GetValue() : nullptr,
2216                                                 pDateItem ? &pDateItem->GetValue() : nullptr );
2217                 }
2218                 else if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
2219                 {
2220                     pTabViewShell->EditNote();                  // note object to edit
2221                 }
2222                 rReq.Done();
2223             }
2224             break;
2225 
2226         case FID_NOTE_VISIBLE:
2227             {
2228                 ScDocument* pDoc = GetViewData()->GetDocument();
2229                 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2230                 if( ScPostIt* pNote = pDoc->GetNote(aPos) )
2231                 {
2232                     bool bShow;
2233                     const SfxPoolItem* pItem;
2234                     if ( pReqArgs && (pReqArgs->GetItemState( FID_NOTE_VISIBLE, true, &pItem ) == SfxItemState::SET) )
2235                         bShow = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2236                     else
2237                         bShow = !pNote->IsCaptionShown();
2238 
2239                     pTabViewShell->ShowNote( bShow );
2240 
2241                     if (!pReqArgs)
2242                         rReq.AppendItem( SfxBoolItem( FID_NOTE_VISIBLE, bShow ) );
2243 
2244                     rReq.Done();
2245                     rBindings.Invalidate( FID_NOTE_VISIBLE );
2246                 }
2247                 else
2248                     rReq.Ignore();
2249             }
2250             break;
2251 
2252         case FID_HIDE_NOTE:
2253         case FID_SHOW_NOTE:
2254             {
2255                 bool bShowNote     = nSlot == FID_SHOW_NOTE;
2256                 ScViewData* pData  = GetViewData();
2257                 ScDocument* pDoc   = pData->GetDocument();
2258                 ScMarkData& rMark  = pData->GetMarkData();
2259 
2260                 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2261                 {
2262                     // Check current cell
2263                     ScAddress aPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2264                     if( pDoc->GetNote(aPos) )
2265                     {
2266                         pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2267                     }
2268                 }
2269                 else
2270                 {
2271                     // Check selection range
2272                     bool bDone = false;
2273                     ScRangeListRef aRangesRef;
2274                     pData->GetMultiArea(aRangesRef);
2275                     const ScRangeList aRanges = *aRangesRef;
2276 
2277                     OUString aUndo = ScResId( bShowNote ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
2278                     pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pData->GetViewShell()->GetViewShellId() );
2279 
2280                     for (auto const& rTab : rMark.GetSelectedTabs())
2281                     {
2282                         // get notes
2283                         std::vector<sc::NoteEntry> aNotes;
2284                         pDoc->GetAllNoteEntries(rTab, aNotes);
2285 
2286                         for (const sc::NoteEntry& rNote : aNotes)
2287                         {
2288                             // check if note is in our selection range
2289                             const ScAddress& rAdr = rNote.maPos;
2290                             const ScRange* rRange = aRanges.Find(rAdr);
2291                             if (! rRange)
2292                                 continue;
2293 
2294                             // check if cell is editable
2295                             const SCTAB nRangeTab = rRange->aStart.Tab();
2296                             if (pDoc->IsBlockEditable( nRangeTab, rAdr.Col(), rAdr.Row(), rAdr.Col(), rAdr.Row() ))
2297                             {
2298                                 pData->GetDocShell()->GetDocFunc().ShowNote( rAdr, bShowNote );
2299                                 bDone = true;
2300                             }
2301                         }
2302                     }
2303 
2304                     pData->GetDocShell()->GetUndoManager()->LeaveListAction();
2305 
2306                     if ( bDone )
2307                     {
2308                         rReq.Done();
2309                         rBindings.Invalidate( nSlot );
2310                     }
2311                     else
2312                          rReq.Ignore();
2313                 }
2314 
2315             }
2316             break;
2317 
2318         case FID_SHOW_ALL_NOTES:
2319         case FID_HIDE_ALL_NOTES:
2320             {
2321                  bool bShowNote     = nSlot == FID_SHOW_ALL_NOTES;
2322                  ScViewData* pData  = GetViewData();
2323                  ScMarkData& rMark  = pData->GetMarkData();
2324                  ScDocument* pDoc   = pData->GetDocument();
2325                  std::vector<sc::NoteEntry> aNotes;
2326 
2327                  OUString aUndo = ScResId( bShowNote ? STR_UNDO_SHOWALLNOTES : STR_UNDO_HIDEALLNOTES );
2328                  pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pData->GetViewShell()->GetViewShellId() );
2329 
2330                  for (auto const& rTab : rMark.GetSelectedTabs())
2331                  {
2332                      pDoc->GetAllNoteEntries(rTab, aNotes);
2333                  }
2334 
2335                  for (const sc::NoteEntry& rNote : aNotes)
2336                  {
2337                      const ScAddress& rAdr = rNote.maPos;
2338                      pData->GetDocShell()->GetDocFunc().ShowNote( rAdr, bShowNote );
2339                  }
2340 
2341                  pData->GetDocShell()->GetUndoManager()->LeaveListAction();
2342             }
2343             break;
2344 
2345         case SID_TOGGLE_NOTES:
2346             {
2347                  ScViewData* pData  = GetViewData();
2348                  ScMarkData& rMark  = pData->GetMarkData();
2349                  ScDocument* pDoc   = pData->GetDocument();
2350                  ScRangeList aRanges;
2351                  std::vector<sc::NoteEntry> aNotes;
2352 
2353                  for (auto const& rTab : rMark.GetSelectedTabs())
2354                      aRanges.push_back(ScRange(0,0,rTab,pDoc->MaxCol(),pDoc->MaxRow(),rTab));
2355 
2356                  CommentCaptionState eState = pDoc->GetAllNoteCaptionsState( aRanges );
2357                  pDoc->GetNotesInRange(aRanges, aNotes);
2358                  bool bShowNote = (eState == ALLHIDDEN || eState == MIXED);
2359 
2360                  OUString aUndo = ScResId( bShowNote ? STR_UNDO_SHOWALLNOTES : STR_UNDO_HIDEALLNOTES );
2361                  pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pData->GetViewShell()->GetViewShellId() );
2362 
2363                  for(const auto& rNote : aNotes)
2364                  {
2365                      const ScAddress& rAdr = rNote.maPos;
2366                      pData->GetDocShell()->GetDocFunc().ShowNote( rAdr, bShowNote );
2367                  }
2368 
2369                  pData->GetDocShell()->GetUndoManager()->LeaveListAction();
2370 
2371                  if (!pReqArgs)
2372                      rReq.AppendItem( SfxBoolItem( SID_TOGGLE_NOTES, bShowNote ) );
2373 
2374                  rReq.Done();
2375                  rBindings.Invalidate( SID_TOGGLE_NOTES );
2376             }
2377             break;
2378 
2379         case SID_DELETE_NOTE:
2380         {
2381             const SfxPoolItem* pId;
2382             // If Id is mentioned, select the appropriate cell first
2383             if ( pReqArgs && pReqArgs->HasItem( SID_ATTR_POSTIT_ID, &pId) )
2384             {
2385                 const SvxPostItIdItem* pIdItem = static_cast<const SvxPostItIdItem*>(pId);
2386                 const OUString& aCellId = pIdItem->GetValue();
2387                 if (!aCellId.isEmpty())
2388                 {
2389                     SetTabNoAndCursor( GetViewData(), aCellId );
2390                 }
2391             }
2392 
2393             pTabViewShell->DeleteContents( InsertDeleteFlags::NOTE );      // delete all notes in selection
2394             rReq.Done();
2395         }
2396         break;
2397 
2398         case FID_DELETE_ALL_NOTES:
2399             {
2400                 ScViewData* pData  = GetViewData();
2401                 ScMarkData& rMark  = pData->GetMarkData();
2402                 ScDocument* pDoc   = pData->GetDocument();
2403                 ScMarkData  aNewMark(pDoc->MaxRow(), pDoc->MaxCol());
2404                 ScRangeList aRangeList;
2405 
2406                 for (auto const& rTab : rMark.GetSelectedTabs())
2407                 {
2408                     aRangeList.push_back(ScRange(0,0,rTab,pDoc->MaxCol(),pDoc->MaxRow(),rTab));
2409                 }
2410 
2411                 aNewMark.MarkFromRangeList( aRangeList, true );
2412                 pData->GetDocShell()->GetDocFunc().DeleteContents(aNewMark, InsertDeleteFlags::NOTE, true, false );
2413             }
2414             break;
2415 
2416         case SID_CHARMAP:
2417             if( pReqArgs != nullptr )
2418             {
2419                 OUString aChars, aFontName;
2420                 const SfxItemSet *pArgs = rReq.GetArgs();
2421                 const SfxPoolItem* pItem = nullptr;
2422                 if ( pArgs )
2423                     pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
2424                 if ( pItem )
2425                 {
2426                     const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( pItem  );
2427                     if ( pStringItem )
2428                         aChars = pStringItem->GetValue();
2429                     const SfxPoolItem* pFtItem = nullptr;
2430                     pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
2431                     const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem  );
2432                     if ( pFontItem )
2433                         aFontName = pFontItem->GetValue();
2434                 }
2435 
2436                 if ( !aChars.isEmpty() )
2437                 {
2438                     vcl::Font aFont;
2439                     pTabViewShell->GetSelectionPattern()->GetFont( aFont, SC_AUTOCOL_BLACK, nullptr, nullptr, nullptr,
2440                                                                 pTabViewShell->GetSelectionScriptType() );
2441                     if ( !aFontName.isEmpty() )
2442                         aFont = vcl::Font( aFontName, Size(1,1) );
2443                     pTabViewShell->InsertSpecialChar( aChars, aFont );
2444                     if( ! rReq.IsAPI() )
2445                         rReq.Done();
2446                 }
2447             }
2448             else
2449             {
2450                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2451 
2452                 // font color doesn't matter here
2453                 vcl::Font         aCurFont;
2454                 pTabViewShell->GetSelectionPattern()->GetFont( aCurFont, SC_AUTOCOL_BLACK, nullptr, nullptr, nullptr,
2455                                                                 pTabViewShell->GetSelectionScriptType() );
2456 
2457                 SfxAllItemSet aSet( GetPool() );
2458                 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
2459                 aSet.Put( SvxFontItem( aCurFont.GetFamilyType(), aCurFont.GetFamilyName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), GetPool().GetWhich(SID_ATTR_CHAR_FONT) ) );
2460                 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
2461                 auto xFrame = pViewFrame->GetFrame().GetFrameInterface();
2462                 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(pTabViewShell->GetFrameWeld(), aSet, xFrame));
2463                 pDlg->Execute();
2464             }
2465             break;
2466 
2467         case SID_SELECT_SCENARIO:
2468             {
2469                 // Testing
2470 
2471                 if ( pReqArgs )
2472                 {
2473                     const SfxStringItem& rItem
2474                         = static_cast<const SfxStringItem&>(pReqArgs->Get(SID_SELECT_SCENARIO));
2475                     pTabViewShell->UseScenario(rItem.GetValue());
2476                     //! why should the return value be valid?!?!
2477                     rReq.SetReturnValue(SfxStringItem(SID_SELECT_SCENARIO, rItem.GetValue()));
2478                     rReq.Done();
2479                 }
2480             }
2481             break;
2482 
2483         case SID_HYPERLINK_SETLINK:
2484             if( pReqArgs )
2485             {
2486                 const SfxPoolItem* pItem;
2487                 if( pReqArgs->HasItem( SID_HYPERLINK_SETLINK, &pItem ) )
2488                 {
2489                     const SvxHyperlinkItem* pHyper = static_cast<const SvxHyperlinkItem*>(pItem);
2490                     const OUString& rName   = pHyper->GetName();
2491                     const OUString& rURL    = pHyper->GetURL();
2492                     const OUString& rTarget = pHyper->GetTargetFrame();
2493                     sal_uInt16 nType = static_cast<sal_uInt16>(pHyper->GetInsertMode());
2494 
2495                     pTabViewShell->InsertURL( rName, rURL, rTarget, nType );
2496                     rReq.Done();
2497                 }
2498                 else
2499                     rReq.Ignore();
2500             }
2501             break;
2502 
2503         case SID_OPENDLG_CONDFRMT_MANAGER:
2504         case SID_OPENDLG_CURRENTCONDFRMT_MANAGER:
2505             {
2506                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2507 
2508                 ScViewData* pData = GetViewData();
2509                 ScDocument* pDoc = pData->GetDocument();
2510 
2511                 if(pDoc->IsTabProtected(pData->GetTabNo()))
2512                 {
2513                     pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
2514                     break;
2515                 }
2516 
2517                 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
2518 
2519                 ScConditionalFormatList* pList = nullptr;
2520 
2521                 const ScCondFormatDlgItem* pDlgItem = nullptr;
2522                 auto itemsRange = pTabViewShell->GetPool().GetItemSurrogates(SCITEM_CONDFORMATDLGDATA);
2523                 if (itemsRange.begin() != itemsRange.end())
2524                 {
2525                     pDlgItem= static_cast<const ScCondFormatDlgItem*>(*itemsRange.begin());
2526                     pList = const_cast<ScCondFormatDlgItem*>(pDlgItem)->GetConditionalFormatList();
2527                 }
2528 
2529                 if (!pList)
2530                     pList = pDoc->GetCondFormList( aPos.Tab() );
2531 
2532                 VclPtr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg(
2533                     pTabViewShell->GetFrameWeld(), pDoc, pList));
2534 
2535                 if (pDlgItem)
2536                     pDlg->SetModified();
2537 
2538                 pDlg->StartExecuteAsync([this, pDlg, pData, pTabViewShell, pDlgItem, aPos](sal_Int32 nRet){
2539                     std::unique_ptr<ScConditionalFormatList> pCondFormatList = pDlg->GetConditionalFormatList();
2540                     if(nRet == RET_OK && pDlg->CondFormatsChanged())
2541                     {
2542                         pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList.release(), aPos.Tab());
2543                     }
2544                     else if(nRet == DLG_RET_ADD)
2545                     {
2546                         // Put the xml string parameter to initialize the
2547                         // Conditional Format Dialog. ( add new )
2548                         pTabViewShell->GetPool().Put(ScCondFormatDlgItem(
2549                                     std::shared_ptr<ScConditionalFormatList>(pCondFormatList.release()), -1, true));
2550                         // Queue message to open Conditional Format Dialog
2551                         GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
2552                     }
2553                     else if (nRet == DLG_RET_EDIT)
2554                     {
2555                         ScConditionalFormat* pFormat = pDlg->GetCondFormatSelected();
2556                         sal_Int32 nIndex = pFormat ? pFormat->GetKey() : -1;
2557                         // Put the xml string parameter to initialize the
2558                         // Conditional Format Dialog. ( edit selected conditional format )
2559                         pTabViewShell->GetPool().Put(ScCondFormatDlgItem(
2560                                     std::shared_ptr<ScConditionalFormatList>(pCondFormatList.release()), nIndex, true));
2561 
2562                         // Queue message to open Conditional Format Dialog
2563                         GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
2564                     }
2565                     else
2566                         pCondFormatList.reset();
2567 
2568                     if (pDlgItem)
2569                         pTabViewShell->GetPool().Remove(*pDlgItem);
2570 
2571                     pDlg->disposeOnce();
2572                 });
2573             }
2574             break;
2575 
2576         case SID_EXTERNAL_SOURCE:
2577             {
2578                 const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>(SID_FILE_NAME);
2579                 const SfxStringItem* pSource = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
2580                 if ( pFile && pSource )
2581                 {
2582                     OUString aFile;
2583                     OUString aFilter;
2584                     OUString aOptions;
2585                     OUString aSource;
2586                     sal_uLong nRefresh=0;
2587 
2588                     aFile = pFile->GetValue();
2589                     aSource = pSource->GetValue();
2590                     const SfxStringItem* pFilter = rReq.GetArg<SfxStringItem>(SID_FILTER_NAME);
2591                     if ( pFilter )
2592                         aFilter = pFilter->GetValue();
2593                     const SfxStringItem* pOptions = rReq.GetArg<SfxStringItem>(SID_FILE_FILTEROPTIONS);
2594                     if ( pOptions )
2595                         aOptions = pOptions->GetValue();
2596                     const SfxUInt32Item* pRefresh = rReq.GetArg<SfxUInt32Item>(FN_PARAM_2);
2597                     if ( pRefresh )
2598                         nRefresh = pRefresh->GetValue();
2599 
2600                     ExecuteExternalSource( aFile, aFilter, aOptions, aSource, nRefresh, rReq );
2601                 }
2602                 else
2603                 {
2604                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2605 
2606                     pImpl->m_pLinkedDlg.disposeAndClear();
2607                     pImpl->m_pLinkedDlg =
2608                         pFact->CreateScLinkedAreaDlg(pTabViewShell->GetFrameWeld());
2609                     delete pImpl->m_pRequest;
2610                     pImpl->m_pRequest = new SfxRequest( rReq );
2611                     OUString sFile, sFilter, sOptions, sSource;
2612                     sal_uLong nRefresh = 0;
2613                     if (pImpl->m_pLinkedDlg->Execute() == RET_OK)
2614                     {
2615                         sFile = pImpl->m_pLinkedDlg->GetURL();
2616                         sFilter = pImpl->m_pLinkedDlg->GetFilter();
2617                         sOptions = pImpl->m_pLinkedDlg->GetOptions();
2618                         sSource = pImpl->m_pLinkedDlg->GetSource();
2619                         nRefresh = pImpl->m_pLinkedDlg->GetRefresh();
2620                         if ( !sFile.isEmpty() )
2621                             pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, sFile ) );
2622                         if ( !sFilter.isEmpty() )
2623                             pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILTER_NAME, sFilter ) );
2624                         if ( !sOptions.isEmpty() )
2625                             pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2626                         if ( !sSource.isEmpty() )
2627                             pImpl->m_pRequest->AppendItem( SfxStringItem( FN_PARAM_1, sSource ) );
2628                         if ( nRefresh )
2629                             pImpl->m_pRequest->AppendItem( SfxUInt32Item( FN_PARAM_2, nRefresh ) );
2630                     }
2631 
2632                     ExecuteExternalSource( sFile, sFilter, sOptions, sSource, nRefresh, *(pImpl->m_pRequest) );
2633                 }
2634             }
2635             break;
2636 
2637         case SID_AUTO_SUM:
2638             {
2639                 bool bSubTotal = false;
2640                 bool bRangeFinder = false;
2641                 const OUString aFormula = pTabViewShell->DoAutoSum( bRangeFinder, bSubTotal , ocSum );
2642                 if ( !aFormula.isEmpty() )
2643                 {
2644                     const sal_Int32 nPar = aFormula.indexOf( '(' );
2645                     const sal_Int32 nLen = aFormula.getLength();
2646                     ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
2647 
2648                     if ( pHdl && nPar != -1 )
2649                     {
2650                         if ( !pScMod->IsEditMode() )
2651                         {
2652                             pScMod->SetInputMode( SC_INPUT_TABLE );
2653                         }
2654 
2655                         EditView *pEditView=pHdl->GetActiveView();
2656                         if ( pEditView )
2657                         {
2658                             ESelection aTextSel = pEditView->GetSelection();
2659                             aTextSel.nStartPos = 0;
2660                             aTextSel.nEndPos = EE_TEXTPOS_ALL;
2661                             pHdl->DataChanging();
2662                             pEditView->SetSelection(aTextSel);
2663                             pEditView->InsertText(aFormula);
2664                             pEditView->SetSelection( bRangeFinder ? ESelection( 0, nPar + ( bSubTotal ? 3 : 1 ), 0, nLen - 1 ) : ESelection( 0, nLen - 1, 0, nLen - 1 ) );
2665                             pHdl->DataChanged();
2666 
2667                             if ( bRangeFinder )
2668                             {
2669                                 pHdl->InitRangeFinder( aFormula );
2670                             }
2671                         }
2672                     }
2673                 }
2674             }
2675             break;
2676 
2677         case SID_SELECT_UNPROTECTED_CELLS:
2678             {
2679                 ScViewData* pData = GetViewData();
2680                 SCTAB aTab = pData->GetTabNo();
2681                 ScMarkData& rMark = pData->GetMarkData();
2682                 ScDocument* pDoc   = pData->GetDocument();
2683                 ScRangeList rRangeList;
2684 
2685                 pDoc->GetUnprotectedCells(rRangeList, aTab);
2686                 rMark.MarkFromRangeList(rRangeList, true);
2687                 pTabViewShell->SetMarkData(rMark);
2688             }
2689             break;
2690 
2691         default:
2692             OSL_FAIL("incorrect slot in ExecuteEdit");
2693             break;
2694     }
2695 }
2696 
ExecuteTrans(SfxRequest & rReq)2697 void ScCellShell::ExecuteTrans( SfxRequest& rReq )
2698 {
2699     TransliterationFlags nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
2700     if ( nType != TransliterationFlags::NONE )
2701     {
2702         GetViewData()->GetView()->TransliterateText( nType );
2703         rReq.Done();
2704     }
2705 }
2706 
ExecuteRotateTrans(const SfxRequest & rReq)2707 void ScCellShell::ExecuteRotateTrans( const SfxRequest& rReq )
2708 {
2709     if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
2710         GetViewData()->GetView()->TransliterateText( m_aRotateCase.getNextMode() );
2711 }
2712 
ExecuteExternalSource(const OUString & _rFile,const OUString & _rFilter,const OUString & _rOptions,const OUString & _rSource,sal_uLong _nRefresh,SfxRequest & _rRequest)2713 void ScCellShell::ExecuteExternalSource(
2714     const OUString& _rFile, const OUString& _rFilter, const OUString& _rOptions,
2715     const OUString& _rSource, sal_uLong _nRefresh, SfxRequest& _rRequest )
2716 {
2717     if ( !_rFile.isEmpty() && !_rSource.isEmpty() )         // filter may be empty
2718     {
2719         ScRange aLinkRange;
2720         bool bMove = false;
2721 
2722         ScViewData* pData = GetViewData();
2723         ScMarkData& rMark = pData->GetMarkData();
2724         rMark.MarkToSimple();
2725         if ( rMark.IsMarked() )
2726         {
2727             rMark.GetMarkArea( aLinkRange );
2728             bMove = true;                       // insert/delete cells to fit range
2729         }
2730         else
2731             aLinkRange = ScRange( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2732 
2733         pData->GetDocFunc().InsertAreaLink( _rFile, _rFilter, _rOptions, _rSource,
2734                                             aLinkRange, _nRefresh, bMove, false );
2735         _rRequest.Done();
2736     }
2737     else
2738         _rRequest.Ignore();
2739 }
2740 
2741 namespace {
2742 
isDPSourceValid(const ScDPObject & rDPObj)2743 bool isDPSourceValid(const ScDPObject& rDPObj)
2744 {
2745     if (rDPObj.IsImportData())
2746     {
2747         // If the data type is database, check if the database is still valid.
2748         const ScImportSourceDesc* pDesc = rDPObj.GetImportSourceDesc();
2749         if (!pDesc)
2750             return false;
2751 
2752         const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
2753         const ScDPDimensionSaveData* pDimData = nullptr;
2754         if (pSaveData)
2755             pDimData = pSaveData->GetExistingDimensionData();
2756 
2757         const ScDPCache* pCache = pDesc->CreateCache(pDimData);
2758         if (!pCache)
2759             // cache creation failed, probably due to invalid connection.
2760             return false;
2761     }
2762     return true;
2763 }
2764 
2765 }
2766 
ExecuteDataPilotDialog()2767 void ScCellShell::ExecuteDataPilotDialog()
2768 {
2769     ScModule* pScMod = SC_MOD();
2770     ScTabViewShell* pTabViewShell   = GetViewData()->GetViewShell();
2771     ScViewData* pData = GetViewData();
2772     ScDocument* pDoc = pData->GetDocument();
2773 
2774     std::unique_ptr<ScDPObject> pNewDPObject;
2775 
2776     // ScPivot is no longer used...
2777     ScDPObject* pDPObj = pDoc->GetDPAtCursor(
2778                                 pData->GetCurX(), pData->GetCurY(),
2779                                 pData->GetTabNo() );
2780     if ( pDPObj )   // on an existing table?
2781     {
2782         if (isDPSourceValid(*pDPObj))
2783             pNewDPObject.reset(new ScDPObject(*pDPObj));
2784     }
2785     else            // create new table
2786     {
2787         const char* pSrcErrorId = nullptr;
2788 
2789         //  select database range or data
2790         pTabViewShell->GetDBData( true, SC_DB_OLD );
2791         ScMarkData& rMark = GetViewData()->GetMarkData();
2792         if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
2793             pTabViewShell->MarkDataArea( false );
2794 
2795         //  output to cursor position for non-sheet data
2796         ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(),
2797                                 pData->GetTabNo() );
2798 
2799         //  first select type of source data
2800 
2801         bool bEnableExt = ScDPObject::HasRegisteredSources();
2802 
2803         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2804 
2805         ScopedVclPtr<AbstractScDataPilotSourceTypeDlg> pTypeDlg(
2806             pFact->CreateScDataPilotSourceTypeDlg(
2807                 pTabViewShell->GetFrameWeld(), bEnableExt));
2808 
2809         // Populate named ranges (if any).
2810         ScRangeName* pRangeName = pDoc->GetRangeName();
2811         if (pRangeName)
2812         {
2813             ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
2814             for (; itr != itrEnd; ++itr)
2815                 pTypeDlg->AppendNamedRange(itr->second->GetName());
2816         }
2817 
2818         if ( pTypeDlg->Execute() == RET_OK )
2819         {
2820             if ( pTypeDlg->IsExternal() )
2821             {
2822                 std::vector<OUString> aSources = ScDPObject::GetRegisteredSources();
2823                 ScopedVclPtr<AbstractScDataPilotServiceDlg> pServDlg(
2824                     pFact->CreateScDataPilotServiceDlg(
2825                         pTabViewShell->GetFrameWeld(), aSources));
2826 
2827                 if ( pServDlg->Execute() == RET_OK )
2828                 {
2829                     ScDPServiceDesc aServDesc(
2830                             pServDlg->GetServiceName(),
2831                             pServDlg->GetParSource(),
2832                             pServDlg->GetParName(),
2833                             pServDlg->GetParUser(),
2834                             pServDlg->GetParPass() );
2835                     pNewDPObject.reset(new ScDPObject(pDoc));
2836                     pNewDPObject->SetServiceData( aServDesc );
2837                 }
2838             }
2839             else if ( pTypeDlg->IsDatabase() )
2840             {
2841                 assert(pFact && "ScAbstractFactory create fail!");
2842                 ScopedVclPtr<AbstractScDataPilotDatabaseDlg> pDataDlg(
2843                     pFact->CreateScDataPilotDatabaseDlg(pTabViewShell->GetFrameWeld()));
2844                 assert(pDataDlg  && "Dialog create fail!");
2845                 if ( pDataDlg->Execute() == RET_OK )
2846                 {
2847                     ScImportSourceDesc aImpDesc(pDoc);
2848                     pDataDlg->GetValues( aImpDesc );
2849                     pNewDPObject.reset(new ScDPObject(pDoc));
2850                     pNewDPObject->SetImportDesc( aImpDesc );
2851                 }
2852             }
2853             else if (pTypeDlg->IsNamedRange())
2854             {
2855                 OUString aName = pTypeDlg->GetSelectedNamedRange();
2856                 ScSheetSourceDesc aShtDesc(pDoc);
2857                 aShtDesc.SetRangeName(aName);
2858                 pSrcErrorId = aShtDesc.CheckSourceRange();
2859                 if (!pSrcErrorId)
2860                 {
2861                     pNewDPObject.reset(new ScDPObject(pDoc));
2862                     pNewDPObject->SetSheetDesc(aShtDesc);
2863                 }
2864             }
2865             else        // selection
2866             {
2867                 //! use database ranges (select before type dialog?)
2868                 ScRange aRange;
2869                 ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
2870                 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
2871                 {
2872                     // Shrink the range to the data area.
2873                     SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
2874                     SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
2875                     if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
2876                     {
2877                         aRange.aStart.SetCol(nStartCol);
2878                         aRange.aStart.SetRow(nStartRow);
2879                         aRange.aEnd.SetCol(nEndCol);
2880                         aRange.aEnd.SetRow(nEndRow);
2881                         rMark.SetMarkArea(aRange);
2882                         pTabViewShell->MarkRange(aRange);
2883                     }
2884 
2885                     bool bOK = true;
2886                     if ( pDoc->HasSubTotalCells( aRange ) )
2887                     {
2888                         //  confirm selection if it contains SubTotal cells
2889                         std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
2890                                                                        VclMessageType::Question, VclButtonsType::YesNo,
2891                                                                        ScResId(STR_DATAPILOT_SUBTOTAL)));
2892                         xQueryBox->set_default_response(RET_YES);
2893                         if (xQueryBox->run() == RET_NO)
2894                             bOK = false;
2895                     }
2896                     if (bOK)
2897                     {
2898                         ScSheetSourceDesc aShtDesc(pDoc);
2899                         aShtDesc.SetSourceRange(aRange);
2900                         pSrcErrorId = aShtDesc.CheckSourceRange();
2901                         if (!pSrcErrorId)
2902                         {
2903                             pNewDPObject.reset(new ScDPObject(pDoc));
2904                             pNewDPObject->SetSheetDesc( aShtDesc );
2905                         }
2906 
2907                         //  output below source data
2908                         if ( aRange.aEnd.Row()+2 <= pDoc->MaxRow() - 4 )
2909                             aDestPos = ScAddress( aRange.aStart.Col(),
2910                                                     aRange.aEnd.Row()+2,
2911                                                     aRange.aStart.Tab() );
2912                     }
2913                 }
2914             }
2915         }
2916 
2917         if (pSrcErrorId)
2918         {
2919             // Error occurred during data creation.  Launch an error and bail out.
2920             std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
2921                                                           VclMessageType::Info, VclButtonsType::Ok,
2922                                                           ScResId(pSrcErrorId)));
2923             xInfoBox->run();
2924             return;
2925         }
2926 
2927         if ( pNewDPObject )
2928             pNewDPObject->SetOutRange( aDestPos );
2929     }
2930 
2931     bool bHadNewDPObject = pNewDPObject != nullptr;
2932     pTabViewShell->SetDialogDPObject( std::move(pNewDPObject) );
2933     if ( bHadNewDPObject )
2934     {
2935         //  start layout dialog
2936 
2937         sal_uInt16 nId  = ScPivotLayoutWrapper::GetChildWindowId();
2938         SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2939         SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2940         pScMod->SetRefDialog( nId, pWnd == nullptr );
2941     }
2942 }
2943 
ExecuteXMLSourceDialog()2944 void ScCellShell::ExecuteXMLSourceDialog()
2945 {
2946     ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2947     if (!pTabViewShell)
2948         return;
2949 
2950     ScModule* pScMod = SC_MOD();
2951 
2952     sal_uInt16 nId = ScXMLSourceDlgWrapper::GetChildWindowId();
2953     SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
2954     SfxChildWindow* pWnd = pViewFrame->GetChildWindow(nId);
2955     pScMod->SetRefDialog(nId, pWnd == nullptr);
2956 }
2957 
ExecuteSubtotals(SfxRequest & rReq)2958 void ScCellShell::ExecuteSubtotals(SfxRequest& rReq)
2959 {
2960     ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2961     const SfxItemSet* pArgs = rReq.GetArgs();
2962     if ( pArgs )
2963     {
2964         pTabViewShell->DoSubTotals( static_cast<const ScSubTotalItem&>( pArgs->Get( SCITEM_SUBTDATA )).
2965                         GetSubTotalData() );
2966         rReq.Done();
2967         return;
2968     }
2969 
2970     ScopedVclPtr<SfxAbstractTabDialog> pDlg;
2971     ScSubTotalParam aSubTotalParam;
2972     SfxItemSet aArgSet( GetPool(), svl::Items<SCITEM_SUBTDATA, SCITEM_SUBTDATA>{} );
2973 
2974     bool bAnonymous;
2975 
2976     // Only get existing named database range.
2977     ScDBData* pDBData = pTabViewShell->GetDBData(true, SC_DB_OLD);
2978     if (pDBData)
2979         bAnonymous = false;
2980     else
2981     {
2982         // No existing DB data at this position.  Create an
2983         // anonymous DB.
2984         bAnonymous = true;
2985         pDBData = pTabViewShell->GetAnonymousDBData();
2986         ScRange aDataRange;
2987         pDBData->GetArea(aDataRange);
2988         pTabViewShell->MarkRange(aDataRange, false);
2989     }
2990 
2991     pDBData->GetSubTotalParam( aSubTotalParam );
2992     aSubTotalParam.bRemoveOnly = false;
2993     if (bAnonymous)
2994     {
2995         // Preset sort formatting along with values and also create formula
2996         // cells with "needs formatting". Subtotals on data of different types
2997         // doesn't make much sense anyway.
2998         aSubTotalParam.bIncludePattern = true;
2999     }
3000 
3001     aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) );
3002     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
3003     pDlg.disposeAndReset(pFact->CreateScSubTotalDlg(pTabViewShell->GetFrameWeld(), &aArgSet));
3004     pDlg->SetCurPageId("1stgroup");
3005 
3006     short bResult = pDlg->Execute();
3007 
3008     if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
3009     {
3010         const SfxItemSet* pOutSet = nullptr;
3011 
3012         if ( bResult == RET_OK )
3013         {
3014             pOutSet = pDlg->GetOutputItemSet();
3015             aSubTotalParam =
3016                 static_cast<const ScSubTotalItem&>(
3017                     pOutSet->Get( SCITEM_SUBTDATA )).
3018                         GetSubTotalData();
3019         }
3020         else // if (bResult == SCRET_REMOVE)
3021         {
3022             pOutSet = &aArgSet;
3023             aSubTotalParam.bRemoveOnly = true;
3024             aSubTotalParam.bReplace    = true;
3025             aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
3026                                          GetViewData(),
3027                                          &aSubTotalParam ) );
3028         }
3029 
3030         pTabViewShell->DoSubTotals( aSubTotalParam );
3031         rReq.Done( *pOutSet );
3032     }
3033     else
3034         GetViewData()->GetDocShell()->CancelAutoDBRange();
3035 }
3036 
ExecuteFillSingleEdit()3037 void ScCellShell::ExecuteFillSingleEdit()
3038 {
3039     ScAddress aCurPos = GetViewData()->GetCurPos();
3040 
3041     OUString aInit;
3042 
3043     if (aCurPos.Row() > 0)
3044     {
3045         // Get the initial text value from the above cell.
3046 
3047         ScDocument* pDoc = GetViewData()->GetDocument();
3048         ScAddress aPrevPos = aCurPos;
3049         aPrevPos.IncRow(-1);
3050         ScRefCellValue aCell(*pDoc, aPrevPos);
3051 
3052         if (aCell.meType == CELLTYPE_FORMULA)
3053         {
3054             aInit = "=";
3055             const ScTokenArray* pCode = aCell.mpFormula->GetCode();
3056             sc::TokenStringContext aCxt(pDoc, pDoc->GetGrammar());
3057             aInit += pCode->CreateString(pDoc, aCxt, aCurPos);
3058         }
3059         else
3060             aInit = aCell.getString(pDoc);
3061     }
3062 
3063     SC_MOD()->SetInputMode(SC_INPUT_TABLE, &aInit);
3064 }
3065 
CellShell_Impl()3066 CellShell_Impl::CellShell_Impl() :
3067         m_pLinkedDlg(),
3068         m_pRequest( nullptr ) {}
3069 
~CellShell_Impl()3070 CellShell_Impl::~CellShell_Impl()
3071 {
3072 }
3073 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
3074