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/processfactory.hxx>
31 #include <comphelper/propertysequence.hxx>
32 #include <comphelper/string.hxx>
33 #include <formula/funcvarargs.h>
34 #include <svl/stritem.hxx>
35 #include <svl/numformat.hxx>
36 #include <svl/zforlist.hxx>
37 #include <svl/zformat.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/request.hxx>
40 #include <vcl/commandinfoprovider.hxx>
41 #include <vcl/unohelp2.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/weld.hxx>
44 #include <svx/svxdlg.hxx>
45 #include <svx/chinese_translation_unodialog.hxx>
46 #include <sot/formats.hxx>
47 #include <svx/postattr.hxx>
48 #include <editeng/fontitem.hxx>
49 #include <svx/clipfmtitem.hxx>
50 #include <svx/hlnkitem.hxx>
51 #include <basic/sbxcore.hxx>
52 #include <editeng/editview.hxx>
53 #include <editeng/urlfieldhelper.hxx>
54 #include <svtools/cliplistener.hxx>
55
56 #include <cellsh.hxx>
57 #include <ftools.hxx>
58 #include <funcdesc.hxx>
59 #include <sc.hrc>
60 #include <document.hxx>
61 #include <patattr.hxx>
62 #include <scmod.hxx>
63 #include <tabvwsh.hxx>
64 #include <uiitems.hxx>
65 #include <reffact.hxx>
66 #include <inputhdl.hxx>
67 #include <transobj.hxx>
68 #include <drwtrans.hxx>
69 #include <docfunc.hxx>
70 #include <editable.hxx>
71 #include <dpobject.hxx>
72 #include <dpsave.hxx>
73 #include <spellparam.hxx>
74 #include <postit.hxx>
75 #include <dpsdbtab.hxx>
76 #include <dpshttab.hxx>
77 #include <dbdata.hxx>
78 #include <docsh.hxx>
79 #include <cliputil.hxx>
80 #include <markdata.hxx>
81 #include <colorscale.hxx>
82 #include <condformatdlg.hxx>
83 #include <attrib.hxx>
84 #include <condformatdlgdata.hxx>
85 #include <impex.hxx>
86
87 #include <globstr.hrc>
88 #include <scresid.hxx>
89 #include <scui_def.hxx>
90 #include <scabstdlg.hxx>
91 #include <tokenstringcontext.hxx>
92 #include <cellvalue.hxx>
93 #include <tokenarray.hxx>
94 #include <formulacell.hxx>
95 #include <gridwin.hxx>
96 #include <searchresults.hxx>
97 #include <Sparkline.hxx>
98
99 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
100 #include <com/sun/star/lang/XInitialization.hpp>
101 #include <com/sun/star/beans/XPropertySet.hpp>
102 #include <com/sun/star/uno/XComponentContext.hpp>
103 #include <o3tl/string_view.hxx>
104
105 #include <memory>
106
107 using namespace ::com::sun::star;
108 using namespace ::com::sun::star::beans;
109 using namespace ::com::sun::star::uno;
110
111 namespace{
FlagsFromString(const OUString & rFlagsStr,InsertDeleteFlags nFlagsMask=InsertDeleteFlags::CONTENTS|InsertDeleteFlags::ATTRIB)112 InsertDeleteFlags FlagsFromString(const OUString& rFlagsStr,
113 InsertDeleteFlags nFlagsMask = InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ATTRIB)
114 {
115 OUString aFlagsStr = rFlagsStr.toAsciiUpperCase();
116 InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
117
118 for (sal_Int32 i=0 ; i < aFlagsStr.getLength(); ++i)
119 {
120 switch (aFlagsStr[i])
121 {
122 case 'A': return InsertDeleteFlags::ALL;
123 case 'S': nFlags |= InsertDeleteFlags::STRING & nFlagsMask; break;
124 case 'V': nFlags |= InsertDeleteFlags::VALUE & nFlagsMask; break;
125 case 'D': nFlags |= InsertDeleteFlags::DATETIME & nFlagsMask; break;
126 case 'F': nFlags |= InsertDeleteFlags::FORMULA & nFlagsMask; break;
127 case 'N': nFlags |= InsertDeleteFlags::NOTE & nFlagsMask; break;
128 case 'T': nFlags |= InsertDeleteFlags::ATTRIB & nFlagsMask; break;
129 case 'O': nFlags |= InsertDeleteFlags::OBJECTS & nFlagsMask; break;
130 }
131 }
132 return nFlags;
133 }
134
FlagsToString(InsertDeleteFlags nFlags,InsertDeleteFlags nFlagsMask=InsertDeleteFlags::CONTENTS|InsertDeleteFlags::ATTRIB)135 OUString FlagsToString( InsertDeleteFlags nFlags,
136 InsertDeleteFlags nFlagsMask = InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ATTRIB )
137 {
138 OUString aFlagsStr;
139
140 if( nFlags == InsertDeleteFlags::ALL )
141 {
142 aFlagsStr = "A";
143 }
144 else
145 {
146 nFlags &= nFlagsMask;
147
148 if( nFlags & InsertDeleteFlags::STRING ) aFlagsStr += "S";
149 if( nFlags & InsertDeleteFlags::VALUE ) aFlagsStr += "V";
150 if( nFlags & InsertDeleteFlags::DATETIME ) aFlagsStr += "D";
151 if( nFlags & InsertDeleteFlags::FORMULA ) aFlagsStr += "F";
152 if( nFlags & InsertDeleteFlags::NOTE ) aFlagsStr += "N";
153 if( nFlags & InsertDeleteFlags::ATTRIB ) aFlagsStr += "T";
154 if( nFlags & InsertDeleteFlags::OBJECTS ) aFlagsStr += "O";
155 }
156 return aFlagsStr;
157 }
158
SetTabNoAndCursor(const ScViewData & rViewData,std::u16string_view rCellId)159 void SetTabNoAndCursor( const ScViewData& rViewData, std::u16string_view rCellId )
160 {
161 ScTabViewShell* pTabViewShell = rViewData.GetViewShell();
162 assert(pTabViewShell);
163 const ScDocument& rDoc = rViewData.GetDocShell().GetDocument();
164 std::vector<sc::NoteEntry> aNotes;
165 rDoc.GetAllNoteEntries(aNotes);
166
167 sal_uInt32 nId = o3tl::toUInt32(rCellId);
168 auto lComp = [nId](const sc::NoteEntry& rNote) { return rNote.mpNote->GetId() == nId; };
169
170 const auto aFoundNoteIt = std::find_if(aNotes.begin(), aNotes.end(), lComp);
171 if (aFoundNoteIt != aNotes.end())
172 {
173 ScAddress aFoundPos = aFoundNoteIt->maPos;
174 pTabViewShell->SetTabNo(aFoundPos.Tab());
175 pTabViewShell->SetCursor(aFoundPos.Col(), aFoundPos.Row());
176 }
177 }
178
HandleConditionalFormat(sal_uInt32 nIndex,bool bCondFormatDlg,bool bContainsCondFormat,const sal_uInt16 nSlot,ScTabViewShell * pTabViewShell)179 void HandleConditionalFormat(sal_uInt32 nIndex, bool bCondFormatDlg, bool bContainsCondFormat,
180 const sal_uInt16 nSlot, ScTabViewShell* pTabViewShell)
181 {
182 condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
183 switch (nSlot)
184 {
185 case SID_OPENDLG_CONDFRMT:
186 case SID_OPENDLG_CURRENTCONDFRMT:
187 eType = condformat::dialog::CONDITION;
188 break;
189 case SID_OPENDLG_COLORSCALE:
190 eType = condformat::dialog::COLORSCALE;
191 break;
192 case SID_OPENDLG_DATABAR:
193 eType = condformat::dialog::DATABAR;
194 break;
195 case SID_OPENDLG_ICONSET:
196 eType = condformat::dialog::ICONSET;
197 break;
198 case SID_OPENDLG_CONDDATE:
199 eType = condformat::dialog::DATE;
200 break;
201 default:
202 assert(false);
203 break;
204 }
205
206 if (bCondFormatDlg || !bContainsCondFormat)
207 {
208 // Put the xml string parameter to initialize the
209 // Conditional Format Dialog. Set the initial DialogData.
210 std::shared_ptr<ScCondFormatDlgData> pDlgData(std::make_shared<ScCondFormatDlgData>(nullptr, nIndex, false));
211 pDlgData->SetDialogType(eType);
212 pTabViewShell->setScCondFormatDlgData(pDlgData);
213
214 sal_uInt16 nId = ScCondFormatDlgWrapper::GetChildWindowId();
215 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
216 SfxChildWindow* pWnd = rViewFrm.GetChildWindow(nId);
217
218 ScModule::get()->SetRefDialog(nId, pWnd == nullptr);
219 }
220 }
221
InsertCells(ScTabViewShell * pTabViewShell,SfxRequest & rReq,InsCellCmd eCmd,size_t nCount=0)222 void InsertCells(ScTabViewShell* pTabViewShell, SfxRequest &rReq, InsCellCmd eCmd, size_t nCount = 0)
223 {
224 if (eCmd!=INS_NONE)
225 {
226 pTabViewShell->InsertCells( eCmd, true, false, nCount );
227
228 if( ! rReq.IsAPI() )
229 {
230 OUString aParam;
231
232 switch( eCmd )
233 {
234 case INS_CELLSDOWN: aParam = "V"; break;
235 case INS_CELLSRIGHT: aParam = ">"; break;
236 case INS_INSROWS_BEFORE: aParam = "R"; break;
237 case INS_INSCOLS_BEFORE: aParam = "C"; break;
238 default:
239 {
240 // added to avoid warnings
241 }
242 }
243 rReq.AppendItem( SfxStringItem( FID_INS_CELL, aParam ) );
244 rReq.Done();
245 }
246 }
247 }
248
DeleteCells(ScTabViewShell * pTabViewShell,SfxRequest & rReq,DelCellCmd eCmd)249 void DeleteCells(ScTabViewShell* pTabViewShell, SfxRequest &rReq, DelCellCmd eCmd)
250 {
251 if (eCmd != DelCellCmd::NONE )
252 {
253 pTabViewShell->DeleteCells( eCmd );
254
255 if( ! rReq.IsAPI() )
256 {
257 OUString aParam;
258
259 switch( eCmd )
260 {
261 case DelCellCmd::CellsUp: aParam = "U"; break;
262 case DelCellCmd::CellsLeft: aParam = "L"; break;
263 case DelCellCmd::Rows: aParam = "R"; break;
264 case DelCellCmd::Cols: aParam = "C"; break;
265 default:
266 {
267 // added to avoid warnings
268 }
269 }
270 rReq.AppendItem( SfxStringItem( FID_DELETE_CELL, aParam ) );
271 rReq.Done();
272 }
273 }
274 }
275 }
276
ExecuteEdit(SfxRequest & rReq)277 void ScCellShell::ExecuteEdit( SfxRequest& rReq )
278 {
279 ScModule* pScMod = ScModule::get();
280 ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
281 SfxBindings& rBindings = pTabViewShell->GetViewFrame().GetBindings();
282 const SfxItemSet* pReqArgs = rReq.GetArgs();
283 sal_uInt16 nSlot = rReq.GetSlot();
284
285 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
286
287 // finish input
288 if ( GetViewData().HasEditView( GetViewData().GetActivePart() ) )
289 {
290 switch ( nSlot )
291 {
292 case FID_DEFINE_NAME:
293 case FID_ADD_NAME:
294 case FID_USE_NAME:
295 case FID_INSERT_NAME:
296 case SID_SPELL_DIALOG:
297 case SID_HANGUL_HANJA_CONVERSION:
298 case SID_OPENDLG_CONDFRMT:
299 case SID_OPENDLG_CURRENTCONDFRMT:
300 case SID_OPENDLG_COLORSCALE:
301 case SID_OPENDLG_DATABAR:
302 pScMod->InputEnterHandler();
303 pTabViewShell->UpdateInputHandler();
304 break;
305
306 default:
307 break;
308 }
309 }
310
311 switch ( nSlot )
312 {
313
314 // insert / delete cells / rows / columns
315
316 case FID_INS_ROW:
317 case FID_INS_ROWS_BEFORE:
318 pTabViewShell->InsertCells(INS_INSROWS_BEFORE);
319 rReq.Done();
320 break;
321
322 case FID_INS_COLUMN:
323 case FID_INS_COLUMNS_BEFORE:
324 pTabViewShell->InsertCells(INS_INSCOLS_BEFORE);
325 rReq.Done();
326 break;
327
328 case FID_INS_ROWS_AFTER:
329 pTabViewShell->InsertCells(INS_INSROWS_AFTER);
330 rReq.Done();
331 break;
332
333 case FID_INS_COLUMNS_AFTER:
334 pTabViewShell->InsertCells(INS_INSCOLS_AFTER);
335 rReq.Done();
336 break;
337
338 case FID_INS_CELLSDOWN:
339 pTabViewShell->InsertCells(INS_CELLSDOWN);
340 rReq.Done();
341 break;
342
343 case FID_INS_CELLSRIGHT:
344 pTabViewShell->InsertCells(INS_CELLSRIGHT);
345 rReq.Done();
346 break;
347
348 case SID_DEL_ROWS:
349 pTabViewShell->DeleteCells( DelCellCmd::Rows );
350 rReq.Done();
351 break;
352
353 case SID_DEL_COLS:
354 pTabViewShell->DeleteCells( DelCellCmd::Cols );
355 rReq.Done();
356 break;
357
358 case FID_INS_CELL:
359 {
360 InsCellCmd eCmd=INS_NONE;
361
362 if ( pReqArgs )
363 {
364 const SfxPoolItem* pItem;
365 OUString aFlags;
366
367 if( pReqArgs->HasItem( FID_INS_CELL, &pItem ) )
368 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
369 if( !aFlags.isEmpty() )
370 {
371 switch( aFlags[0] )
372 {
373 case 'V': eCmd = INS_CELLSDOWN ;break;
374 case '>': eCmd = INS_CELLSRIGHT ;break;
375 case 'R': eCmd = INS_INSROWS_BEFORE ;break;
376 case 'C': eCmd = INS_INSCOLS_BEFORE ;break;
377 }
378 }
379 }
380 else
381 {
382 if ( GetViewData().SimpleColMarked() )
383 eCmd = INS_INSCOLS_BEFORE;
384 else if ( GetViewData().SimpleRowMarked() )
385 eCmd = INS_INSROWS_BEFORE;
386 else
387 {
388 ScDocument& rDoc = GetViewData().GetDocument();
389 bool bTheFlag=(rDoc.GetChangeTrack()!=nullptr);
390
391 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
392
393 VclPtr<AbstractScInsertCellDlg> pDlg(pFact->CreateScInsertCellDlg(pTabViewShell->GetFrameWeld(), GetViewData(), bTheFlag));
394 pDlg->StartExecuteAsync([pDlg, pTabViewShell](sal_Int32 nResult){
395 if (nResult == RET_OK)
396 {
397 SfxRequest aRequest(pTabViewShell->GetViewFrame(), FID_INS_CELL);
398 InsCellCmd eTmpCmd = pDlg->GetInsCellCmd();
399 size_t nInsCount = pDlg->GetCount();
400 InsertCells(pTabViewShell, aRequest, eTmpCmd, nInsCount);
401 }
402 pDlg->disposeOnce();
403 });
404 break;
405 }
406 }
407
408 InsertCells(pTabViewShell, rReq, eCmd);
409 }
410 break;
411
412 case FID_DELETE_CELL:
413 {
414 DelCellCmd eCmd = DelCellCmd::NONE;
415
416 if ( pReqArgs )
417 {
418 const SfxPoolItem* pItem;
419 OUString aFlags;
420
421 if( pReqArgs->HasItem( FID_DELETE_CELL, &pItem ) )
422 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
423 if( !aFlags.isEmpty() )
424 {
425 switch( aFlags[0] )
426 {
427 case 'U': eCmd = DelCellCmd::CellsUp ;break;
428 case 'L': eCmd = DelCellCmd::CellsLeft ;break;
429 case 'R': eCmd = DelCellCmd::Rows ;break;
430 case 'C': eCmd = DelCellCmd::Cols ;break;
431 }
432 }
433 }
434 else
435 {
436 if ( GetViewData().SimpleColMarked() )
437 eCmd = DelCellCmd::Cols;
438 else if ( GetViewData().SimpleRowMarked() )
439 eCmd = DelCellCmd::Rows;
440 else
441 {
442 ScRange aRange;
443 ScDocument& rDoc = GetViewData().GetDocument();
444 bool bTheFlag=GetViewData().IsMultiMarked() ||
445 (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE_FILTERED) ||
446 (rDoc.GetChangeTrack() != nullptr);
447
448 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
449 VclPtr<AbstractScDeleteCellDlg> pDlg(pFact->CreateScDeleteCellDlg( pTabViewShell->GetFrameWeld(), bTheFlag ));
450
451 pDlg->StartExecuteAsync([pDlg, pTabViewShell](sal_Int32 nResult){
452 if (nResult == RET_OK)
453 {
454 SfxRequest aRequest(pTabViewShell->GetViewFrame(), FID_INS_CELL);
455 DeleteCells(pTabViewShell, aRequest, pDlg->GetDelCellCmd());
456 }
457 pDlg->disposeOnce();
458 });
459 }
460 }
461 DeleteCells(pTabViewShell, rReq, eCmd);
462 }
463 break;
464
465 // delete contents from cells
466
467 case SID_DELETE_CONTENTS:
468 pTabViewShell->DeleteContents( InsertDeleteFlags::CONTENTS );
469 rReq.Done();
470 break;
471
472 case SID_DELETE:
473 {
474 InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
475
476 if ( pReqArgs!=nullptr && pTabViewShell->SelectionEditable() )
477 {
478 const SfxPoolItem* pItem;
479 OUString aFlags('A');
480
481 if( pReqArgs->HasItem( SID_DELETE, &pItem ) )
482 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
483
484 nFlags |= FlagsFromString(aFlags, InsertDeleteFlags::ALL);
485 }
486 else
487 {
488 ScEditableTester aTester( pTabViewShell );
489 if (aTester.IsEditable())
490 {
491 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
492
493 ScopedVclPtr<AbstractScDeleteContentsDlg> pDlg(pFact->CreateScDeleteContentsDlg(pTabViewShell->GetFrameWeld()));
494 ScDocument& rDoc = GetViewData().GetDocument();
495 SCTAB nTab = GetViewData().GetTabNo();
496 if ( rDoc.IsTabProtected(nTab) )
497 pDlg->DisableObjects();
498 if (pDlg->Execute() == RET_OK)
499 {
500 nFlags = pDlg->GetDelContentsCmdBits();
501 }
502 }
503 else
504 pTabViewShell->ErrorMessage(aTester.GetMessageId());
505 }
506
507 if( nFlags != InsertDeleteFlags::NONE )
508 {
509 pTabViewShell->DeleteContents( nFlags );
510
511 if( ! rReq.IsAPI() )
512 {
513 OUString aFlags = FlagsToString( nFlags, InsertDeleteFlags::ALL );
514
515 rReq.AppendItem( SfxStringItem( SID_DELETE, aFlags ) );
516 rReq.Done();
517 }
518 }
519 }
520 break;
521
522 // fill...
523
524 case FID_FILL_TO_BOTTOM:
525 pTabViewShell->FillSimple( FILL_TO_BOTTOM );
526 rReq.Done();
527 break;
528
529 case FID_FILL_TO_RIGHT:
530 pTabViewShell->FillSimple( FILL_TO_RIGHT );
531 rReq.Done();
532 break;
533
534 case FID_FILL_TO_TOP:
535 pTabViewShell->FillSimple( FILL_TO_TOP );
536 rReq.Done();
537 break;
538
539 case FID_FILL_TO_LEFT:
540 pTabViewShell->FillSimple( FILL_TO_LEFT );
541 rReq.Done();
542 break;
543
544 case FID_FILL_TAB:
545 {
546 InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
547 ScPasteFunc nFunction = ScPasteFunc::NONE;
548 bool bSkipEmpty = false;
549 bool bAsLink = false;
550
551 if ( pReqArgs!=nullptr && pTabViewShell->SelectionEditable() )
552 {
553 const SfxPoolItem* pItem;
554 OUString aFlags('A');
555
556 if( pReqArgs->HasItem( FID_FILL_TAB, &pItem ) )
557 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
558
559 nFlags |= FlagsFromString(aFlags);
560 }
561 else
562 {
563 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
564
565 ScopedVclPtr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg(pTabViewShell->GetFrameWeld(),
566 new OUString(ScResId(STR_FILL_TAB))));
567 pDlg->SetFillMode(true);
568
569 if (pDlg->Execute() == RET_OK)
570 {
571 nFlags = pDlg->GetInsContentsCmdBits();
572 nFunction = pDlg->GetFormulaCmdBits();
573 bSkipEmpty = pDlg->IsSkipEmptyCells();
574 bAsLink = pDlg->IsLink();
575 // there is no MoveMode with fill tabs
576 }
577 }
578
579 if( nFlags != InsertDeleteFlags::NONE )
580 {
581 pTabViewShell->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
582
583 if( ! rReq.IsAPI() )
584 {
585 OUString aFlags = FlagsToString( nFlags );
586
587 rReq.AppendItem( SfxStringItem( FID_FILL_TAB, aFlags ) );
588 rReq.Done();
589 }
590 }
591 }
592 break;
593
594 case FID_FILL_SERIES:
595 {
596 if (GetViewData().SelectionForbidsCellFill())
597 // Slot should be already disabled, but in case it wasn't
598 // don't even attempt to do the evaluation and popup a
599 // dialog.
600 break;
601
602 SCCOL nStartCol;
603 SCROW nStartRow;
604 SCTAB nStartTab;
605 SCCOL nEndCol;
606 SCROW nEndRow;
607 SCTAB nEndTab;
608 sal_uInt16 nPossDir = FDS_OPT_NONE;
609 FillDir eFillDir = FILL_TO_BOTTOM;
610 FillCmd eFillCmd = FILL_LINEAR;
611 FillDateCmd eFillDateCmd = FILL_DAY;
612 double fStartVal = MAXDOUBLE;
613 double fIncVal = 1;
614 double fMaxVal = MAXDOUBLE;
615 bool bDoIt = false;
616
617 GetViewData().GetSimpleArea( nStartCol, nStartRow, nStartTab,
618 nEndCol, nEndRow, nEndTab );
619
620 if( nStartCol!=nEndCol )
621 {
622 nPossDir |= FDS_OPT_HORZ;
623 eFillDir=FILL_TO_RIGHT;
624 }
625
626 if( nStartRow!=nEndRow )
627 {
628 nPossDir |= FDS_OPT_VERT;
629 eFillDir=FILL_TO_BOTTOM;
630 }
631
632 ScDocument& rDoc = GetViewData().GetDocument();
633 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
634
635 if( pReqArgs )
636 {
637 const SfxPoolItem* pItem;
638 OUString aFillDir, aFillCmd, aFillDateCmd;
639 OUString aFillStep, aFillStart, aFillMax;
640 sal_uInt32 nKey;
641 double fTmpVal;
642
643 if( pReqArgs->HasItem( FID_FILL_SERIES, &pItem ) )
644 aFillDir = static_cast<const SfxStringItem*>(pItem)->GetValue();
645 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
646 aFillCmd = static_cast<const SfxStringItem*>(pItem)->GetValue();
647 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
648 aFillDateCmd = static_cast<const SfxStringItem*>(pItem)->GetValue();
649 if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) )
650 aFillStep = static_cast<const SfxStringItem*>(pItem)->GetValue();
651 if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
652 aFillStart = static_cast<const SfxStringItem*>(pItem)->GetValue();
653 if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
654 aFillMax = static_cast<const SfxStringItem*>(pItem)->GetValue();
655
656 if( !aFillDir.isEmpty() )
657 switch( aFillDir[0] )
658 {
659 case 'B': case 'b': eFillDir=FILL_TO_BOTTOM; break;
660 case 'R': case 'r': eFillDir=FILL_TO_RIGHT; break;
661 case 'T': case 't': eFillDir=FILL_TO_TOP; break;
662 case 'L': case 'l': eFillDir=FILL_TO_LEFT; break;
663 }
664
665 if( !aFillCmd.isEmpty() )
666 switch( aFillCmd[0] )
667 {
668 case 'S': case 's': eFillCmd=FILL_SIMPLE; break;
669 case 'L': case 'l': eFillCmd=FILL_LINEAR; break;
670 case 'G': case 'g': eFillCmd=FILL_GROWTH; break;
671 case 'D': case 'd': eFillCmd=FILL_DATE; break;
672 case 'A': case 'a': eFillCmd=FILL_AUTO; break;
673 }
674
675 if( !aFillDateCmd.isEmpty() )
676 switch( aFillDateCmd[0] )
677 {
678 case 'D': case 'd': eFillDateCmd=FILL_DAY; break;
679 case 'W': case 'w': eFillDateCmd=FILL_WEEKDAY; break;
680 case 'M': case 'm': eFillDateCmd=FILL_MONTH; break;
681 case 'Y': case 'y': eFillDateCmd=FILL_YEAR; break;
682 }
683
684 nKey = 0;
685 if( pFormatter->IsNumberFormat( aFillStart, nKey, fTmpVal ))
686 fStartVal = fTmpVal;
687
688 nKey = 0;
689 if( pFormatter->IsNumberFormat( aFillStep, nKey, fTmpVal ))
690 fIncVal = fTmpVal;
691
692 nKey = 0;
693 if( pFormatter->IsNumberFormat( aFillMax, nKey, fTmpVal ))
694 fMaxVal = fTmpVal;
695
696 bDoIt = true;
697
698 }
699 else // (pReqArgs == nullptr) => raise Dialog
700 {
701 sal_uInt32 nPrivFormat = rDoc.GetNumberFormat( nStartCol, nStartRow, nStartTab );
702 CellType eCellType = rDoc.GetCellType( nStartCol, nStartRow, nStartTab );
703 const SvNumberformat* pPrivEntry = pFormatter->GetEntry( nPrivFormat );
704 const SCSIZE nSelectHeight = nEndRow - nStartRow + 1;
705 const SCSIZE nSelectWidth = nEndCol - nStartCol + 1;
706
707 if (!pPrivEntry)
708 {
709 OSL_FAIL("Numberformat not found !!!");
710 }
711 else
712 {
713 SvNumFormatType nPrivType = pPrivEntry->GetType();
714 if (nPrivType & SvNumFormatType::DATE)
715 {
716 eFillCmd=FILL_DATE;
717 }
718 else if(eCellType==CELLTYPE_STRING)
719 {
720 eFillCmd=FILL_AUTO;
721 }
722 }
723
724 OUString aStartStr;
725
726 // suggest default Startvalue only, when just 1 row or column
727 if ( nStartCol == nEndCol || nStartRow == nEndRow )
728 {
729 double fInputEndVal = 0.0;
730 OUString aEndStr;
731
732 const bool forceSystemLocale = true;
733 aStartStr = rDoc.GetInputString( nStartCol, nStartRow, nStartTab, forceSystemLocale );
734 fStartVal = rDoc.GetValue( nStartCol, nStartRow, nStartTab );
735
736 if(eFillDir==FILL_TO_BOTTOM && nStartRow < nEndRow )
737 {
738 aEndStr = rDoc.GetInputString( nStartCol, nStartRow+1, nStartTab, forceSystemLocale );
739 if(!aEndStr.isEmpty())
740 {
741 fInputEndVal = rDoc.GetValue( nStartCol, nStartRow+1, nStartTab );
742 fIncVal=fInputEndVal-fStartVal;
743 }
744 }
745 else
746 {
747 if(nStartCol < nEndCol)
748 {
749 aEndStr = rDoc.GetInputString( nStartCol+1, nStartRow, nStartTab, forceSystemLocale );
750 if(!aEndStr.isEmpty())
751 {
752 fInputEndVal = rDoc.GetValue( nStartCol+1, nStartRow, nStartTab );
753 fIncVal=fInputEndVal-fStartVal;
754 }
755 }
756 }
757 if(eFillCmd==FILL_DATE)
758 {
759 const Date& rNullDate = rDoc.GetFormatTable()->GetNullDate();
760 Date aStartDate = rNullDate;
761 aStartDate.AddDays(fStartVal);
762 Date aEndDate = rNullDate;
763 aEndDate.AddDays(fInputEndVal);
764 double fTempDate=0;
765
766 if(aStartDate.GetYear()!=aEndDate.GetYear())
767 {
768 eFillDateCmd = FILL_YEAR;
769 fTempDate=aEndDate.GetYear()-aStartDate.GetYear();
770 }
771 if(aStartDate.GetMonth()!=aEndDate.GetMonth())
772 {
773 eFillDateCmd = FILL_MONTH;
774 fTempDate=fTempDate*12+aEndDate.GetMonth()-aStartDate.GetMonth();
775 }
776 if(aStartDate.GetDay()==aEndDate.GetDay())
777 {
778 fIncVal=fTempDate;
779 }
780 }
781 }
782 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
783
784 ScopedVclPtr<AbstractScFillSeriesDlg> pDlg(pFact->CreateScFillSeriesDlg( pTabViewShell->GetFrameWeld(),
785 rDoc,
786 eFillDir, eFillCmd, eFillDateCmd,
787 aStartStr, fIncVal, fMaxVal,
788 nSelectHeight, nSelectWidth, nPossDir));
789
790 if ( nStartCol != nEndCol && nStartRow != nEndRow )
791 {
792 pDlg->SetEdStartValEnabled(false);
793 }
794
795 if ( pDlg->Execute() == RET_OK )
796 {
797 eFillDir = pDlg->GetFillDir();
798 eFillCmd = pDlg->GetFillCmd();
799 eFillDateCmd = pDlg->GetFillDateCmd();
800
801 if(eFillCmd==FILL_AUTO)
802 {
803 OUString aStr = pDlg->GetStartStr();
804 if(!aStr.isEmpty())
805 pTabViewShell->EnterData( nStartCol, nStartRow, nStartTab, aStr );
806 }
807 fStartVal = pDlg->GetStart();
808 fIncVal = pDlg->GetStep();
809 fMaxVal = pDlg->GetMax();
810 bDoIt = true;
811 }
812 }
813
814 if( bDoIt )
815 {
816 //nScFillModeMouseModifier = 0; // no Ctrl/Copy
817 pTabViewShell->FillSeries( eFillDir, eFillCmd, eFillDateCmd, fStartVal, fIncVal, fMaxVal );
818
819 if( ! rReq.IsAPI() )
820 {
821 OUString aPara;
822 const Color* pColor = nullptr;
823
824 switch( eFillDir )
825 {
826 case FILL_TO_BOTTOM: aPara = "B"; break;
827 case FILL_TO_RIGHT: aPara = "R"; break;
828 case FILL_TO_TOP: aPara = "T"; break;
829 case FILL_TO_LEFT: aPara = "L"; break;
830 default: break;
831 }
832 rReq.AppendItem( SfxStringItem( FID_FILL_SERIES, aPara ) );
833
834 switch( eFillCmd )
835 {
836 case FILL_SIMPLE: aPara = "S"; break;
837 case FILL_LINEAR: aPara = "L"; break;
838 case FILL_GROWTH: aPara = "G"; break;
839 case FILL_DATE: aPara = "D"; break;
840 case FILL_AUTO: aPara = "A"; break;
841 default: break;
842 }
843 rReq.AppendItem( SfxStringItem( FN_PARAM_1, aPara ) );
844
845 switch( eFillDateCmd )
846 {
847 case FILL_DAY: aPara = "D"; break;
848 case FILL_WEEKDAY: aPara = "W"; break;
849 case FILL_MONTH: aPara = "M"; break;
850 case FILL_YEAR: aPara = "Y"; break;
851 default: break;
852 }
853 rReq.AppendItem( SfxStringItem( FN_PARAM_2, aPara ) );
854
855 sal_uInt32 nFormatKey = pFormatter->GetStandardFormat(SvNumFormatType::NUMBER,
856 ScGlobal::eLnge );
857
858 pFormatter->GetOutputString( fIncVal, nFormatKey, aPara, &pColor );
859 rReq.AppendItem( SfxStringItem( FN_PARAM_3, aPara ) );
860
861 pFormatter->GetOutputString( fStartVal, nFormatKey, aPara, &pColor );
862 rReq.AppendItem( SfxStringItem( FN_PARAM_4, aPara ) );
863
864 pFormatter->GetOutputString( fMaxVal, nFormatKey, aPara, &pColor );
865 rReq.AppendItem( SfxStringItem( FN_PARAM_5, aPara ) );
866
867 rReq.Done();
868 }
869 }
870 }
871 break;
872
873 case FID_FILL_AUTO:
874 {
875 SCCOL nStartCol;
876 SCROW nStartRow;
877 SCCOL nEndCol;
878 SCROW nEndRow;
879
880 GetViewData().GetFillData( nStartCol, nStartRow, nEndCol, nEndRow );
881 SCCOL nFillCol = GetViewData().GetRefEndX();
882 SCROW nFillRow = GetViewData().GetRefEndY();
883 ScDocument& rDoc = GetViewData().GetDocument();
884
885 sal_uInt16 nOrigScFillModeMouseModifier = nScFillModeMouseModifier;
886 bool bUseSelection = true;
887
888 if( pReqArgs != nullptr )
889 {
890 if( const SfxStringItem* pItem = pReqArgs->GetItemIfSet( FID_FILL_AUTO ) )
891 {
892 ScAddress aScAddress;
893 OUString aArg = pItem->GetValue();
894
895 if( aScAddress.Parse( aArg, rDoc, rDoc.GetAddressConvention() ) & ScRefFlags::VALID )
896 {
897 nFillRow = aScAddress.Row();
898 nFillCol = aScAddress.Col();
899 }
900
901 SCTAB nStartTab, nEndTab;
902 GetViewData().GetSimpleArea(nStartCol, nStartRow, nStartTab, nEndCol,
903 nEndRow, nEndTab);
904 bUseSelection = false;
905 }
906
907 const SfxPoolItem* pItem;
908 if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
909 {
910 /*
911 nScFillModeMouseModifier controls if we "Copy cells" or "Fill series"
912 - if nScFillModeMouseModifier is set to "KEY_MOD1", use "Copy cells"
913 - otherwise use "Fill series"
914
915 This is also the same with auto fill by dragging mouse
916 - dragging with Ctrl key will set nScFillModeMouseModifier to KEY_MOD1, use "Copy cells"
917 - only dragging will use "Fill series" (no Ctrl key)
918 */
919 const bool bCopyCells = static_cast<const SfxBoolItem*>(pItem)->GetValue();
920 nScFillModeMouseModifier &= ~KEY_MOD1; // turn off, reset to 0
921
922 if (bCopyCells)
923 nScFillModeMouseModifier |= KEY_MOD1; // turn on
924 }
925 }
926 if (bUseSelection) // call via mouse or if FN_PARAM_1 exists
927 {
928 // not in a merged cell
929
930 if ( nStartCol == nEndCol && nStartRow == nEndRow )
931 {
932 SCCOL nMergeCol = nStartCol;
933 SCROW nMergeRow = nStartRow;
934 if ( GetViewData().GetDocument().ExtendMerge(
935 nStartCol, nStartRow, nMergeCol, nMergeRow,
936 GetViewData().GetTabNo() ) )
937 {
938 if ( nFillCol >= nStartCol && nFillCol <= nMergeCol && nFillRow == nStartRow )
939 nFillCol = nStartCol;
940 if ( nFillRow >= nStartRow && nFillRow <= nMergeRow && nFillCol == nStartCol )
941 nFillRow = nStartRow;
942 }
943 }
944 }
945
946 if ( nFillCol != nEndCol || nFillRow != nEndRow )
947 {
948 if ( nFillCol==nEndCol || nFillRow==nEndRow )
949 {
950 FillDir eDir = FILL_TO_BOTTOM;
951 SCCOLROW nCount = 0;
952
953 if ( nFillCol==nEndCol )
954 {
955 if ( nFillRow > nEndRow )
956 {
957 eDir = FILL_TO_BOTTOM;
958 nCount = nFillRow - nEndRow;
959 }
960 else if ( nFillRow < nStartRow )
961 {
962 eDir = FILL_TO_TOP;
963 nCount = nStartRow - nFillRow;
964 }
965 }
966 else
967 {
968 if ( nFillCol > nEndCol )
969 {
970 eDir = FILL_TO_RIGHT;
971 nCount = nFillCol - nEndCol;
972 }
973 else if ( nFillCol < nStartCol )
974 {
975 eDir = FILL_TO_LEFT;
976 nCount = nStartCol - nFillCol;
977 }
978 }
979
980 if ( nCount != 0)
981 {
982 pTabViewShell->FillAuto( eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount );
983
984 if( ! rReq.IsAPI() )
985 {
986 ScAddress aAdr( nFillCol, nFillRow, 0 );
987 OUString aAdrStr(aAdr.Format(ScRefFlags::RANGE_ABS, &rDoc, rDoc.GetAddressConvention()));
988
989 rReq.AppendItem( SfxStringItem( FID_FILL_AUTO, aAdrStr ) );
990 rReq.Done();
991 }
992 }
993
994 }
995 else
996 {
997 OSL_FAIL( "Direction not unique for autofill" );
998 }
999 }
1000
1001 // reset nScFillModeMouseModifier to its original state
1002 // otherwise, auto fill by dragging will not work as expected
1003 nScFillModeMouseModifier = nOrigScFillModeMouseModifier;
1004 }
1005 break;
1006 case FID_FILL_SINGLE_EDIT:
1007 ExecuteFillSingleEdit();
1008 break;
1009 case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
1010 {
1011 sal_uInt16 nId = ScRandomNumberGeneratorDialogWrapper::GetChildWindowId();
1012 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1013 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1014
1015 pScMod->SetRefDialog( nId, pWnd == nullptr );
1016
1017 }
1018 break;
1019 case SID_SAMPLING_DIALOG:
1020 {
1021 sal_uInt16 nId = ScSamplingDialogWrapper::GetChildWindowId();
1022 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1023 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1024
1025 pScMod->SetRefDialog( nId, pWnd == nullptr );
1026 }
1027 break;
1028 case SID_DESCRIPTIVE_STATISTICS_DIALOG:
1029 {
1030 sal_uInt16 nId = ScDescriptiveStatisticsDialogWrapper::GetChildWindowId();
1031 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1032 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1033
1034 pScMod->SetRefDialog( nId, pWnd == nullptr );
1035 }
1036 break;
1037 case SID_ANALYSIS_OF_VARIANCE_DIALOG:
1038 {
1039 sal_uInt16 nId = ScAnalysisOfVarianceDialogWrapper::GetChildWindowId();
1040 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1041 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1042
1043 pScMod->SetRefDialog( nId, pWnd == nullptr );
1044 }
1045 break;
1046 case SID_CORRELATION_DIALOG:
1047 {
1048 sal_uInt16 nId = ScCorrelationDialogWrapper::GetChildWindowId();
1049 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1050 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1051
1052 pScMod->SetRefDialog( nId, pWnd == nullptr );
1053 }
1054 break;
1055 case SID_COVARIANCE_DIALOG:
1056 {
1057 sal_uInt16 nId = ScCovarianceDialogWrapper::GetChildWindowId();
1058 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1059 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1060
1061 pScMod->SetRefDialog( nId, pWnd == nullptr );
1062 }
1063 break;
1064 case SID_EXPONENTIAL_SMOOTHING_DIALOG:
1065 {
1066 sal_uInt16 nId = ScExponentialSmoothingDialogWrapper::GetChildWindowId();
1067 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1068 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1069
1070 pScMod->SetRefDialog( nId, pWnd == nullptr );
1071 }
1072 break;
1073 case SID_MOVING_AVERAGE_DIALOG:
1074 {
1075 sal_uInt16 nId = ScMovingAverageDialogWrapper::GetChildWindowId();
1076 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1077 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1078
1079 pScMod->SetRefDialog( nId, pWnd == nullptr );
1080 }
1081 break;
1082 case SID_REGRESSION_DIALOG:
1083 {
1084 sal_uInt16 nId = ScRegressionDialogWrapper::GetChildWindowId();
1085 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1086 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1087
1088 pScMod->SetRefDialog( nId, pWnd == nullptr );
1089 }
1090 break;
1091 case SID_TTEST_DIALOG:
1092 {
1093 sal_uInt16 nId = ScTTestDialogWrapper::GetChildWindowId();
1094 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1095 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1096
1097 pScMod->SetRefDialog( nId, pWnd == nullptr );
1098
1099 }
1100 break;
1101 case SID_FTEST_DIALOG:
1102 {
1103 sal_uInt16 nId = ScFTestDialogWrapper::GetChildWindowId();
1104 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1105 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1106
1107 pScMod->SetRefDialog( nId, pWnd == nullptr );
1108
1109 }
1110 break;
1111 case SID_ZTEST_DIALOG:
1112 {
1113 sal_uInt16 nId = ScZTestDialogWrapper::GetChildWindowId();
1114 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1115 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1116
1117 pScMod->SetRefDialog( nId, pWnd == nullptr );
1118
1119 }
1120 break;
1121 case SID_CHI_SQUARE_TEST_DIALOG:
1122 {
1123 sal_uInt16 nId = ScChiSquareTestDialogWrapper::GetChildWindowId();
1124 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1125 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1126
1127 pScMod->SetRefDialog( nId, pWnd == nullptr );
1128
1129 }
1130 break;
1131 case SID_FOURIER_ANALYSIS_DIALOG:
1132 {
1133 sal_uInt16 nId = ScFourierAnalysisDialogWrapper::GetChildWindowId();
1134 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1135 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
1136
1137 pScMod->SetRefDialog( nId, pWnd == nullptr );
1138
1139 }
1140 break;
1141 case SID_SEARCH_RESULTS_DIALOG:
1142 {
1143 const SfxPoolItem* pItem = nullptr;
1144 if (pReqArgs && pReqArgs->HasItem(SID_SEARCH_RESULTS_DIALOG, &pItem))
1145 {
1146 bool bVisible = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1147 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
1148 // The window ID should equal the slot ID, but not a biggie if it wasn't.
1149 sal_uInt16 nId = sc::SearchResultsDlgWrapper::GetChildWindowId();
1150 rViewFrm.SetChildWindow(nId, bVisible, false);
1151 }
1152 rReq.Done();
1153 }
1154 break;
1155
1156 case SID_INSERT_SPARKLINE:
1157 case SID_EDIT_SPARKLINE_GROUP:
1158 {
1159 sal_uInt16 nId = sc::SparklineDialogWrapper::GetChildWindowId();
1160 SfxViewFrame& rViewFrame = pTabViewShell->GetViewFrame();
1161 SfxChildWindow* pWindow = rViewFrame.GetChildWindow(nId);
1162 pScMod->SetRefDialog(nId, pWindow == nullptr);
1163 rReq.Done();
1164 }
1165 break;
1166
1167 case SID_EDIT_SPARKLINE:
1168 {
1169 sal_uInt16 nId = sc::SparklineDataRangeDialogWrapper::GetChildWindowId();
1170 SfxViewFrame& rViewFrame = pTabViewShell->GetViewFrame();
1171 SfxChildWindow* pWindow = rViewFrame.GetChildWindow(nId);
1172 pScMod->SetRefDialog(nId, pWindow == nullptr);
1173 rReq.Done();
1174 }
1175 break;
1176
1177 case SID_DELETE_SPARKLINE:
1178 {
1179 pTabViewShell->DeleteContents(InsertDeleteFlags::SPARKLINES);
1180
1181 rReq.Done();
1182 }
1183 break;
1184
1185 case SID_DELETE_SPARKLINE_GROUP:
1186 {
1187 ScRange aMarkRange;
1188 ScMarkType eMarkType = GetViewData().GetSimpleArea(aMarkRange);
1189 if (eMarkType == SC_MARK_SIMPLE)
1190 {
1191 std::shared_ptr<sc::SparklineGroup> pSparklineGroup;
1192 if (GetViewData().GetDocument().GetSparklineGroupInRange(aMarkRange, pSparklineGroup) && pSparklineGroup)
1193 {
1194 GetViewData().GetDocShell().GetDocFunc().DeleteSparklineGroup(pSparklineGroup, GetViewData().GetTabNo());
1195 }
1196 }
1197 rReq.Done();
1198 }
1199 break;
1200
1201 case SID_GROUP_SPARKLINES:
1202 {
1203 ScRange aRange;
1204 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1205 {
1206 ScAddress aCursorAddress(GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo());
1207 auto pSparkline = GetViewData().GetDocument().GetSparkline(aCursorAddress);
1208 if (pSparkline)
1209 {
1210 auto const& rpSparklineGroup = pSparkline->getSparklineGroup();
1211 GetViewData().GetDocShell().GetDocFunc().GroupSparklines(aRange, rpSparklineGroup);
1212 }
1213 }
1214 rReq.Done();
1215 }
1216 break;
1217
1218 case SID_UNGROUP_SPARKLINES:
1219 {
1220 ScRange aRange;
1221 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1222 {
1223 GetViewData().GetDocShell().GetDocFunc().UngroupSparklines(aRange);
1224 }
1225 rReq.Done();
1226 }
1227 break;
1228
1229 // disposal (Outlines)
1230 // SID_AUTO_OUTLINE, SID_OUTLINE_DELETEALL in Execute (in docsh.idl)
1231
1232 case SID_OUTLINE_HIDE:
1233 if ( GetViewData().GetDocument().GetDPAtCursor( GetViewData().GetCurX(),
1234 GetViewData().GetCurY(), GetViewData().GetTabNo() ) )
1235 pTabViewShell->SetDataPilotDetails( false );
1236 else
1237 pTabViewShell->HideMarkedOutlines();
1238 rReq.Done();
1239 break;
1240
1241 case SID_OUTLINE_SHOW:
1242 {
1243 ScDPObject* pDPObj = GetViewData().GetDocument().GetDPAtCursor( GetViewData().GetCurX(),
1244 GetViewData().GetCurY(), GetViewData().GetTabNo() );
1245 if ( pDPObj )
1246 {
1247 Sequence<sheet::DataPilotFieldFilter> aFilters;
1248 css::sheet::DataPilotFieldOrientation nOrientation;
1249 if ( pTabViewShell->HasSelectionForDrillDown( nOrientation ) )
1250 {
1251 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1252 ScopedVclPtr<AbstractScDPShowDetailDlg> pDlg( pFact->CreateScDPShowDetailDlg(
1253 pTabViewShell->GetFrameWeld(), *pDPObj, nOrientation ) );
1254 if ( pDlg->Execute() == RET_OK )
1255 {
1256 OUString aNewDimName( pDlg->GetDimensionName() );
1257 pTabViewShell->SetDataPilotDetails( true, &aNewDimName );
1258 }
1259 }
1260 else if ( !pDPObj->IsServiceData() &&
1261 pDPObj->GetDataFieldPositionData(
1262 ScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() ),
1263 aFilters ) )
1264 pTabViewShell->ShowDataPilotSourceData( *pDPObj, aFilters );
1265 else
1266 pTabViewShell->SetDataPilotDetails(true);
1267 }
1268 else
1269 pTabViewShell->ShowMarkedOutlines();
1270 rReq.Done();
1271 }
1272 break;
1273
1274 case SID_OUTLINE_MAKE:
1275 {
1276 bool bColumns = false;
1277 bool bOk = true;
1278
1279 if ( GetViewData().GetDocument().GetDPAtCursor( GetViewData().GetCurX(),
1280 GetViewData().GetCurY(), GetViewData().GetTabNo() ) )
1281 {
1282 ScDPNumGroupInfo aNumInfo;
1283 aNumInfo.mbEnable = true;
1284 aNumInfo.mbAutoStart = true;
1285 aNumInfo.mbAutoEnd = true;
1286 sal_Int32 nParts = 0;
1287 if ( pTabViewShell->HasSelectionForDateGroup( aNumInfo, nParts ) )
1288 {
1289 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1290 const Date& rNullDate( GetViewData().GetDocument().GetFormatTable()->GetNullDate() );
1291 ScopedVclPtr<AbstractScDPDateGroupDlg> pDlg( pFact->CreateScDPDateGroupDlg(
1292 pTabViewShell->GetFrameWeld(),
1293 aNumInfo, nParts, rNullDate ) );
1294 if( pDlg->Execute() == RET_OK )
1295 {
1296 aNumInfo = pDlg->GetGroupInfo();
1297 pTabViewShell->DateGroupDataPilot( aNumInfo, pDlg->GetDatePart() );
1298 }
1299 }
1300 else if ( pTabViewShell->HasSelectionForNumGroup( aNumInfo ) )
1301 {
1302 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1303 ScopedVclPtr<AbstractScDPNumGroupDlg> pDlg( pFact->CreateScDPNumGroupDlg(
1304 pTabViewShell->GetFrameWeld(), aNumInfo ) );
1305 if( pDlg->Execute() == RET_OK )
1306 pTabViewShell->NumGroupDataPilot( pDlg->GetGroupInfo() );
1307 }
1308 else
1309 pTabViewShell->GroupDataPilot();
1310
1311 bOk = false;
1312 }
1313 else if( pReqArgs != nullptr )
1314 {
1315 const SfxPoolItem* pItem;
1316 bOk = false;
1317
1318 if( pReqArgs->HasItem( SID_OUTLINE_MAKE, &pItem ) )
1319 {
1320 OUString aCol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1321 aCol = aCol.toAsciiUpperCase();
1322
1323 switch( aCol[0] )
1324 {
1325 case 'R': bColumns=false; bOk = true;break;
1326 case 'C': bColumns=true; bOk = true;break;
1327 }
1328 }
1329 }
1330 else // Dialog, when not whole rows/columns are marked
1331 {
1332 if ( GetViewData().SimpleColMarked() && !GetViewData().SimpleRowMarked() )
1333 bColumns = true;
1334 else if ( !GetViewData().SimpleColMarked() && GetViewData().SimpleRowMarked() )
1335 bColumns = false;
1336 else
1337 {
1338 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1339
1340 VclPtr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetFrameWeld()));
1341
1342 pDlg->StartExecuteAsync(
1343 [pDlg, pTabViewShell] (sal_Int32 nResult) {
1344 if( RET_OK == nResult )
1345 {
1346 bool bColumn = pDlg->GetColsChecked();
1347 pTabViewShell->MakeOutline( bColumn );
1348 }
1349 pDlg->disposeOnce();
1350 }
1351 );
1352
1353 bOk = false;
1354 }
1355 }
1356 if (bOk)
1357 {
1358 pTabViewShell->MakeOutline( bColumns );
1359
1360 if( ! rReq.IsAPI() )
1361 {
1362 OUString aCol = bColumns ? OUString('C') : OUString('R');
1363 rReq.AppendItem( SfxStringItem( SID_OUTLINE_MAKE, aCol ) );
1364 rReq.Done();
1365 }
1366 }
1367 }
1368 break;
1369
1370 case SID_OUTLINE_REMOVE:
1371 {
1372 bool bColumns = false;
1373 bool bOk = true;
1374
1375 if ( GetViewData().GetDocument().GetDPAtCursor( GetViewData().GetCurX(),
1376 GetViewData().GetCurY(), GetViewData().GetTabNo() ) )
1377 {
1378 pTabViewShell->UngroupDataPilot();
1379 bOk = false;
1380 }
1381 else if( pReqArgs != nullptr )
1382 {
1383 const SfxPoolItem* pItem;
1384 bOk = false;
1385
1386 if( pReqArgs->HasItem( SID_OUTLINE_REMOVE, &pItem ) )
1387 {
1388 OUString aCol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1389 aCol = aCol.toAsciiUpperCase();
1390
1391 switch (aCol[0])
1392 {
1393 case 'R': bColumns=false; bOk = true;break;
1394 case 'C': bColumns=true; bOk = true;break;
1395 }
1396 }
1397 }
1398 else // Dialog only when removal for rows and columns is possible
1399 {
1400 bool bColPoss, bRowPoss;
1401 pTabViewShell->TestRemoveOutline( bColPoss, bRowPoss );
1402 // TODO: handle this case in LOK too
1403 if ( bColPoss && bRowPoss && !comphelper::LibreOfficeKit::isActive() )
1404 {
1405 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1406
1407 VclPtr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetFrameWeld(), true));
1408
1409 pDlg->StartExecuteAsync(
1410 [pDlg, pTabViewShell] (sal_Int32 nResult) {
1411 if( RET_OK == nResult )
1412 {
1413 bool bColumn = pDlg->GetColsChecked();
1414 pTabViewShell->RemoveOutline( bColumn );
1415 }
1416 pDlg->disposeOnce();
1417 }
1418 );
1419
1420 bOk = false;
1421 }
1422 else if ( bColPoss )
1423 bColumns = true;
1424 else if ( bRowPoss )
1425 bColumns = false;
1426 else
1427 bOk = false;
1428 }
1429 if (bOk)
1430 {
1431 pTabViewShell->RemoveOutline( bColumns );
1432
1433 if( ! rReq.IsAPI() )
1434 {
1435 OUString aCol = bColumns ? OUString('C') : OUString('R');
1436 rReq.AppendItem( SfxStringItem( SID_OUTLINE_REMOVE, aCol ) );
1437 rReq.Done();
1438 }
1439 }
1440 }
1441 break;
1442
1443 // Clipboard
1444
1445 case SID_COPY: // for graphs in DrawShell
1446 {
1447 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1448 pTabViewShell->CopyToClip( nullptr, false, false, true );
1449 rReq.Done();
1450
1451 if (!comphelper::LibreOfficeKit::isActive() || !pTabViewShell->GetViewShell() || !pTabViewShell->GetViewShell()->IsLokReadOnlyView())
1452 GetViewData().SetPasteMode( ScPasteFlags::Mode | ScPasteFlags::Border );
1453
1454 pTabViewShell->ShowCursor();
1455 pTabViewShell->UpdateCopySourceOverlay();
1456 }
1457 break;
1458
1459 case SID_CUT: // for graphs in DrawShell
1460 {
1461 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1462 pTabViewShell->CutToClip();
1463 rReq.Done();
1464
1465 if (!comphelper::LibreOfficeKit::isActive() || !pTabViewShell->GetViewShell() || !pTabViewShell->GetViewShell()->IsLokReadOnlyView())
1466 GetViewData().SetPasteMode( ScPasteFlags::Mode | ScPasteFlags::Border );
1467
1468 pTabViewShell->ShowCursor();
1469 pTabViewShell->UpdateCopySourceOverlay();
1470 }
1471 break;
1472
1473 case SID_COPYDELETE: // for graphs in DrawShell
1474 {
1475 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1476 pTabViewShell->CopyToClip( nullptr, true, false, true );
1477 pTabViewShell->DeleteContents( InsertDeleteFlags::CONTENTS );
1478 rReq.Done();
1479 GetViewData().SetPasteMode( ScPasteFlags::Mode | ScPasteFlags::Border );
1480 pTabViewShell->ShowCursor();
1481 pTabViewShell->UpdateCopySourceOverlay();
1482 }
1483 break;
1484 case SID_PASTE:
1485 {
1486 ScClipUtil::PasteFromClipboard( GetViewData(), pTabViewShell, true );
1487 rReq.Done();
1488 }
1489 break;
1490
1491 case SID_CLIPBOARD_FORMAT_ITEMS:
1492 {
1493 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1494
1495 SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
1496 const SfxPoolItem* pItem;
1497 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
1498 if (auto pIntItem = dynamic_cast<const SfxUInt32Item*>(pItem) )
1499 nFormat = static_cast<SotClipboardFormatId>(pIntItem->GetValue());
1500
1501 if ( nFormat != SotClipboardFormatId::NONE )
1502 {
1503 css::uno::Reference<css::datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(GetViewData().GetActiveWin()));
1504 bool bCells = ( ScTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1505 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1506 bool bOle = ( nFormat == SotClipboardFormatId::EMBED_SOURCE );
1507
1508 if ( bCells && bOle )
1509 pTabViewShell->PasteFromSystem();
1510 else if ( bDraw && bOle )
1511 pTabViewShell->PasteDraw();
1512 else
1513 pTabViewShell->PasteFromSystem(nFormat);
1514 }
1515 //?else
1516 //? pTabViewShell->PasteFromSystem();
1517
1518 rReq.Done();
1519 }
1520 pTabViewShell->CellContentChanged();
1521 break;
1522
1523 case FID_INS_CELL_CONTENTS:
1524 {
1525 ScDocument& rDoc = GetViewData().GetDocument();
1526 bool bOtherDoc = !rDoc.IsClipboardSource();
1527 // keep a reference in case the clipboard is changed during dialog or PasteFromClip
1528 const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(GetViewData().GetActiveWin()));
1529 if ( pOwnClip )
1530 {
1531 InsertDeleteFlags nFlags = InsertDeleteFlags::NONE;
1532 ScPasteFunc nFunction = ScPasteFunc::NONE;
1533 InsCellCmd eMoveMode = INS_NONE;
1534 bool bSkipEmpty = false;
1535 bool bTranspose = false;
1536 bool bAsLink = false;
1537
1538 if ( pReqArgs!=nullptr && pTabViewShell->SelectionEditable() )
1539 {
1540 const SfxPoolItem* pItem;
1541 OUString aFlags('A');
1542
1543 if( pReqArgs->HasItem( FID_INS_CELL_CONTENTS, &pItem ) )
1544 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
1545
1546 nFlags |= FlagsFromString(aFlags);
1547
1548 const SfxUInt16Item* pFuncItem = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
1549 const SfxBoolItem* pSkipItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_2);
1550 const SfxBoolItem* pTransposeItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_3);
1551 const SfxBoolItem* pLinkItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_4);
1552 const SfxInt16Item* pMoveItem = rReq.GetArg<SfxInt16Item>(FN_PARAM_5);
1553 if ( pFuncItem )
1554 nFunction = static_cast<ScPasteFunc>(pFuncItem->GetValue());
1555 if ( pSkipItem )
1556 bSkipEmpty = pSkipItem->GetValue();
1557 if ( pTransposeItem )
1558 bTranspose = pTransposeItem->GetValue();
1559 if ( pLinkItem )
1560 bAsLink = pLinkItem->GetValue();
1561 if ( pMoveItem )
1562 eMoveMode = static_cast<InsCellCmd>(pMoveItem->GetValue());
1563 }
1564 else
1565 {
1566 ScEditableTester aTester( pTabViewShell );
1567 if (aTester.IsEditable())
1568 {
1569 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1570
1571 ScopedVclPtr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg(pTabViewShell->GetFrameWeld()));
1572 pDlg->SetOtherDoc( bOtherDoc );
1573 // if ChangeTrack MoveMode disable
1574 pDlg->SetChangeTrack( rDoc.GetChangeTrack() != nullptr );
1575 // fdo#56098 disable shift if necessary
1576 if (!bOtherDoc)
1577 {
1578 ScViewData& rData = GetViewData();
1579 if ( rData.GetMarkData().GetTableSelect( rData.GetTabNo() ) )
1580 {
1581 SCCOL nStartX, nEndX, nClipStartX, nClipSizeX, nRangeSizeX;
1582 SCROW nStartY, nEndY, nClipStartY, nClipSizeY, nRangeSizeY;
1583 SCTAB nStartTab, nEndTab;
1584 pOwnClip->GetDocument()->GetClipStart( nClipStartX, nClipStartY );
1585 pOwnClip->GetDocument()->GetClipArea( nClipSizeX, nClipSizeY, true );
1586
1587 if ( rData.GetSimpleArea( nStartX, nStartY, nStartTab,
1588 nEndX, nEndY, nEndTab ) != SC_MARK_SIMPLE ||
1589 nStartTab != nEndTab )
1590 {
1591 // the destination is not a simple range,
1592 // assume the destination as the current cell
1593 nStartX = nEndX = rData.GetCurX();
1594 nStartY = nEndY = rData.GetCurY();
1595 nStartTab = rData.GetTabNo();
1596 }
1597 // we now have clip- and range dimensions
1598 // the size of the destination area is the larger of the two
1599 nRangeSizeX = nClipSizeX >= nEndX - nStartX ? nClipSizeX : nEndX - nStartX;
1600 nRangeSizeY = nClipSizeY >= nEndY - nStartY ? nClipSizeY : nEndY - nStartY;
1601 // When the source and destination areas intersect things may go wrong,
1602 // especially if the area contains references. This may produce data loss
1603 // (e.g. formulas that get wrong references), this scenario _must_ be avoided.
1604 ScRange aSource( nClipStartX, nClipStartY, nStartTab,
1605 nClipStartX + nClipSizeX, nClipStartY + nClipSizeY, nStartTab );
1606 ScRange aDest( nStartX, nStartY, nStartTab,
1607 nStartX + nRangeSizeX, nStartY + nRangeSizeY, nStartTab );
1608 if ( pOwnClip->GetDocument()->IsCutMode() && aSource.Intersects( aDest ) )
1609 pDlg->SetCellShiftDisabled( CellShiftDisabledFlags::Down | CellShiftDisabledFlags::Right );
1610 else
1611 {
1612 //no conflict with intersecting ranges,
1613 //check if paste plus shift will fit on sheet
1614 //and disable shift-option if no fit
1615 CellShiftDisabledFlags nDisableShiftX = CellShiftDisabledFlags::NONE;
1616 CellShiftDisabledFlags nDisableShiftY = CellShiftDisabledFlags::NONE;
1617
1618 //check if horizontal shift will fit
1619 if ( !rData.GetDocument().IsBlockEmpty(
1620 rDoc.MaxCol() - nRangeSizeX, nStartY,
1621 rDoc.MaxCol(), nStartY + nRangeSizeY,
1622 nStartTab ) )
1623 nDisableShiftX = CellShiftDisabledFlags::Right;
1624
1625 //check if vertical shift will fit
1626 if ( !rData.GetDocument().IsBlockEmpty(
1627 nStartX, rDoc.MaxRow() - nRangeSizeY,
1628 nStartX + nRangeSizeX, rDoc.MaxRow(),
1629 nStartTab ) )
1630 nDisableShiftY = CellShiftDisabledFlags::Down;
1631
1632 if ( nDisableShiftX != CellShiftDisabledFlags::NONE || nDisableShiftY != CellShiftDisabledFlags::NONE)
1633 pDlg->SetCellShiftDisabled( nDisableShiftX | nDisableShiftY );
1634 }
1635 }
1636 }
1637 if (pDlg->Execute() == RET_OK)
1638 {
1639 nFlags = pDlg->GetInsContentsCmdBits();
1640 nFunction = pDlg->GetFormulaCmdBits();
1641 bSkipEmpty = pDlg->IsSkipEmptyCells();
1642 bTranspose = pDlg->IsTranspose();
1643 bAsLink = pDlg->IsLink();
1644 eMoveMode = pDlg->GetMoveMode();
1645 }
1646 }
1647 else
1648 pTabViewShell->ErrorMessage(aTester.GetMessageId());
1649 }
1650
1651 if( nFlags != InsertDeleteFlags::NONE )
1652 {
1653 {
1654 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1655 if ( bAsLink && bOtherDoc )
1656 pTabViewShell->PasteFromSystem(SotClipboardFormatId::LINK); // DDE insert
1657 else
1658 {
1659 pTabViewShell->PasteFromClip( nFlags, pOwnClip->GetDocument(),
1660 nFunction, bSkipEmpty, bTranspose, bAsLink,
1661 eMoveMode, InsertDeleteFlags::NONE, true ); // allow warning dialog
1662 }
1663 }
1664
1665 if( !pReqArgs )
1666 {
1667 OUString aFlags = FlagsToString( nFlags );
1668
1669 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1670 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bSkipEmpty ) );
1671 rReq.AppendItem( SfxBoolItem( FN_PARAM_3, bTranspose ) );
1672 rReq.AppendItem( SfxBoolItem( FN_PARAM_4, bAsLink ) );
1673 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nFunction) ) );
1674 rReq.AppendItem( SfxInt16Item( FN_PARAM_5, static_cast<sal_Int16>(eMoveMode) ) );
1675 rReq.Done();
1676 }
1677 }
1678 }
1679 }
1680 pTabViewShell->CellContentChanged(); // => PasteFromXXX ???
1681 break;
1682 case SID_PASTE_ONLY_VALUE:
1683 case SID_PASTE_ONLY_TEXT:
1684 case SID_PASTE_ONLY_FORMULA:
1685 {
1686 if ( ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(GetViewData().GetActiveWin())) ) // own cell data
1687 {
1688 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1689 OUString aFlags;
1690 if ( nSlot == SID_PASTE_ONLY_VALUE )
1691 aFlags = "V";
1692 else if ( nSlot == SID_PASTE_ONLY_TEXT )
1693 aFlags = "S";
1694 else
1695 aFlags = "F";
1696 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1697 ExecuteSlot( rReq, GetInterface() );
1698 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1699 pTabViewShell->CellContentChanged();
1700 }
1701 else
1702 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1703 break;
1704 }
1705 case SID_PASTE_TRANSPOSED:
1706 {
1707 if (ScTransferObj::GetOwnClipboard(
1708 ScTabViewShell::GetClipData(GetViewData().GetActiveWin()))) // own cell data
1709 {
1710 rReq.SetSlot(FID_INS_CELL_CONTENTS);
1711 // By default content (values/numbers, strings, formulas and dates),
1712 // attributes and notes are pasted
1713 rReq.AppendItem(SfxBoolItem(FN_PARAM_3, true)); // transpose
1714 ExecuteSlot(rReq, GetInterface());
1715 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1716 pTabViewShell->CellContentChanged();
1717 }
1718 else
1719 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1720 break;
1721 }
1722 case SID_PASTE_AS_LINK:
1723 {
1724 if (ScTransferObj::GetOwnClipboard(
1725 ScTabViewShell::GetClipData(GetViewData().GetActiveWin()))) // own cell data
1726 {
1727 rReq.SetSlot(FID_INS_CELL_CONTENTS);
1728 // paste links to values/numbers, strings, formulas and dates
1729 // do not paste attributes, notes and objects
1730 rReq.AppendItem(SfxStringItem(FID_INS_CELL_CONTENTS, u"VSFD"_ustr));
1731 rReq.AppendItem(SfxBoolItem(FN_PARAM_4, true)); // as link
1732 ExecuteSlot(rReq, GetInterface());
1733 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1734 pTabViewShell->CellContentChanged();
1735 }
1736 else
1737 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1738 break;
1739 }
1740 case SID_PASTE_TEXTIMPORT_DIALOG:
1741 {
1742 vcl::Window* pWin = GetViewData().GetActiveWin();
1743 TransferableDataHelper aDataHelper(
1744 TransferableDataHelper::CreateFromSystemClipboard(pWin));
1745 const uno::Reference<datatransfer::XTransferable>& xTransferable
1746 = aDataHelper.GetTransferable();
1747 SotClipboardFormatId format = SotClipboardFormatId::STRING;
1748 bool bSuccess = false;
1749 if (xTransferable.is() && HasClipboardFormat(format))
1750 {
1751 OUString sStrBuffer;
1752 bSuccess = aDataHelper.GetString(format, sStrBuffer);
1753 if (bSuccess)
1754 {
1755 auto pStrm = std::make_shared<ScImportStringStream>(sStrBuffer);
1756 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1757 VclPtr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg(
1758 pWin ? pWin->GetFrameWeld() : nullptr, OUString(), pStrm.get(), SC_PASTETEXT));
1759 ScRange aRange;
1760 SCCOL nPosX = 0;
1761 SCROW nPosY = 0;
1762 if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1763 {
1764 nPosX = aRange.aStart.Col();
1765 nPosY = aRange.aStart.Row();
1766 }
1767 else
1768 {
1769 nPosX = GetViewData().GetCurX();
1770 nPosY = GetViewData().GetCurY();
1771 }
1772 ScAddress aCellPos(nPosX, nPosY, GetViewData().GetTabNo());
1773 auto pObj = std::make_shared<ScImportExport>(GetViewData().GetDocument(), aCellPos);
1774 pObj->SetOverwriting(true);
1775 if (pDlg->Execute()) {
1776 ScAsciiOptions aOptions;
1777 pDlg->GetOptions(aOptions);
1778 pDlg->SaveParameters();
1779 pObj->SetExtOptions(aOptions);
1780 pObj->ImportString(sStrBuffer, format);
1781 }
1782 pDlg->disposeOnce();
1783 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success, 0 = fail
1784 rReq.Done();
1785 }
1786 }
1787 if (!bSuccess)
1788 {
1789 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1790 rReq.Ignore();
1791 }
1792 }
1793 break;
1794 case SID_PASTE_SPECIAL:
1795 // differentiate between own cell data and draw objects/external data
1796 // this makes FID_INS_CELL_CONTENTS superfluous
1797 {
1798 vcl::Window* pWin = GetViewData().GetActiveWin();
1799 css::uno::Reference<css::datatransfer::XTransferable2> xTransferable(ScTabViewShell::GetClipData(pWin));
1800
1801 // Clipboard-ID given as parameter? Basic "PasteSpecial(Format)"
1802 const SfxPoolItem* pItem=nullptr;
1803 if ( pReqArgs &&
1804 pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET &&
1805 dynamic_cast<const SfxUInt32Item*>( pItem) != nullptr )
1806 {
1807 SotClipboardFormatId nFormat = static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pItem)->GetValue());
1808 bool bRet=true;
1809 {
1810 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1811 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1812 if ( bDraw && nFormat == SotClipboardFormatId::EMBED_SOURCE )
1813 pTabViewShell->PasteDraw();
1814 else
1815 bRet = pTabViewShell->PasteFromSystem(nFormat, true); // TRUE: no error messages
1816 }
1817
1818 if ( bRet )
1819 {
1820 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success, 0 = fail
1821 rReq.Done();
1822 }
1823 else
1824 // if format is not available -> fallback to request without parameters
1825 pItem = nullptr;
1826 }
1827
1828 if ( !pItem )
1829 {
1830 if ( ScTransferObj::GetOwnClipboard(xTransferable) ) // own cell data
1831 {
1832 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1833 ExecuteSlot( rReq, GetInterface() );
1834 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1835 }
1836 else // draw objects or external data
1837 {
1838 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard(xTransferable) != nullptr );
1839
1840 SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1841 GetPossibleClipboardFormats( aFormats );
1842
1843 sal_uInt16 nFormatCount = aFormats.Count();
1844 if ( nFormatCount )
1845 {
1846 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1847 ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(pTabViewShell->GetFrameWeld()));
1848 for (sal_uInt16 i=0; i<nFormatCount; i++)
1849 {
1850 SotClipboardFormatId nFormatId = aFormats.GetClipbrdFormatId( i );
1851 OUString aName = aFormats.GetClipbrdFormatName( i );
1852 // special case for paste dialog: '*' is replaced by object type
1853 if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE )
1854 aName = "*";
1855 pDlg->Insert( nFormatId, aName );
1856 }
1857
1858 SfxViewFrame& rViewFrame = pTabViewShell->GetViewFrame();
1859 auto xFrame = rViewFrame.GetFrame().GetFrameInterface();
1860 const OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(xFrame));
1861 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(u".uno:PasteTextImportDialog"_ustr, aModuleName);
1862 OUString sLabel(vcl::CommandInfoProvider::GetTooltipLabelForCommand(aProperties));
1863 pDlg->InsertUno(u".uno:PasteTextImportDialog"_ustr, sLabel);
1864
1865 TransferableDataHelper aDataHelper(
1866 TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
1867 SotClipboardFormatId nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
1868 if (nFormat != SotClipboardFormatId::NONE)
1869 {
1870 {
1871 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1872 if ( bDraw && nFormat == SotClipboardFormatId::EMBED_SOURCE )
1873 pTabViewShell->PasteDraw();
1874 else
1875 pTabViewShell->PasteFromSystem(nFormat);
1876 }
1877 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1878 rReq.AppendItem( SfxUInt32Item( nSlot, static_cast<sal_uInt32>(nFormat) ) );
1879 rReq.Done();
1880 }
1881 else
1882 {
1883 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1884 rReq.Ignore();
1885 }
1886 }
1887 else
1888 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1889 }
1890 }
1891 }
1892 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
1893 break;
1894
1895 case SID_PASTE_UNFORMATTED:
1896 // differentiate between own cell data and draw objects/external data
1897 // this makes FID_INS_CELL_CONTENTS superfluous
1898 {
1899 weld::WaitObject aWait( GetViewData().GetDialogParent() );
1900
1901 // we should differentiate between SotClipboardFormatId::STRING and SotClipboardFormatId::STRING_TSVC,
1902 // and paste the SotClipboardFormatId::STRING_TSVC if it is available.
1903 // Which makes a difference if the clipboard contains cells with embedded line breaks.
1904
1905 SotClipboardFormatId nFormat = HasClipboardFormat( SotClipboardFormatId::STRING_TSVC) ?
1906 SotClipboardFormatId::STRING_TSVC : SotClipboardFormatId::STRING;
1907
1908 const bool bRet = pTabViewShell->PasteFromSystem(nFormat, true); // TRUE: no error messages
1909 if ( bRet )
1910 {
1911 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1912 rReq.Done();
1913 }
1914 else
1915 {
1916 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1917 }
1918
1919 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
1920 }
1921 break;
1922
1923 // other
1924
1925 case FID_INS_ROWBRK:
1926 pTabViewShell->InsertPageBreak( false );
1927 rReq.Done();
1928 break;
1929
1930 case FID_INS_COLBRK:
1931 pTabViewShell->InsertPageBreak( true );
1932 rReq.Done();
1933 break;
1934
1935 case FID_DEL_ROWBRK:
1936 pTabViewShell->DeletePageBreak( false );
1937 rReq.Done();
1938 break;
1939
1940 case FID_DEL_COLBRK:
1941 pTabViewShell->DeletePageBreak( true );
1942 rReq.Done();
1943 break;
1944
1945 case SID_DETECTIVE_ADD_PRED:
1946 pTabViewShell->DetectiveAddPred();
1947 rReq.Done();
1948 break;
1949
1950 case SID_DETECTIVE_DEL_PRED:
1951 pTabViewShell->DetectiveDelPred();
1952 rReq.Done();
1953 break;
1954
1955 case SID_DETECTIVE_ADD_SUCC:
1956 pTabViewShell->DetectiveAddSucc();
1957 rReq.Done();
1958 break;
1959
1960 case SID_DETECTIVE_DEL_SUCC:
1961 pTabViewShell->DetectiveDelSucc();
1962 rReq.Done();
1963 break;
1964
1965 case SID_DETECTIVE_ADD_ERR:
1966 pTabViewShell->DetectiveAddError();
1967 rReq.Done();
1968 break;
1969
1970 case SID_DETECTIVE_INVALID:
1971 pTabViewShell->DetectiveMarkInvalid();
1972 rReq.Done();
1973 break;
1974
1975 case SID_DETECTIVE_REFRESH:
1976 pTabViewShell->DetectiveRefresh();
1977 rReq.Done();
1978 break;
1979
1980 case SID_DETECTIVE_MARK_PRED:
1981 pTabViewShell->DetectiveMarkPred();
1982 break;
1983 case SID_DETECTIVE_MARK_SUCC:
1984 pTabViewShell->DetectiveMarkSucc();
1985 break;
1986 case SID_INSERT_CURRENT_DATE:
1987 pTabViewShell->InsertCurrentTime(
1988 SvNumFormatType::DATE, ScResId(STR_UNDO_INSERT_CURRENT_DATE));
1989 break;
1990 case SID_INSERT_CURRENT_TIME:
1991 pTabViewShell->InsertCurrentTime(
1992 SvNumFormatType::TIME, ScResId(STR_UNDO_INSERT_CURRENT_TIME));
1993 break;
1994
1995 case SID_SPELL_DIALOG:
1996 {
1997 SfxViewFrame& rViewFrame = pTabViewShell->GetViewFrame();
1998 if( rReq.GetArgs() )
1999 rViewFrame.SetChildWindow( SID_SPELL_DIALOG,
2000 static_cast< const SfxBoolItem& >( rReq.GetArgs()->
2001 Get( SID_SPELL_DIALOG ) ).GetValue() );
2002 else
2003 rViewFrame.ToggleChildWindow( SID_SPELL_DIALOG );
2004
2005 rViewFrame.GetBindings().Invalidate( SID_SPELL_DIALOG );
2006 rReq.Ignore();
2007 }
2008 break;
2009
2010 case SID_HANGUL_HANJA_CONVERSION:
2011 pTabViewShell->DoHangulHanjaConversion();
2012 break;
2013
2014 case SID_CHINESE_CONVERSION:
2015 {
2016 //open ChineseTranslationDialog
2017 rtl::Reference< textconversiondlgs::ChineseTranslation_UnoDialog > xDialog(new textconversiondlgs::ChineseTranslation_UnoDialog({}));
2018
2019 //execute dialog
2020 sal_Int16 nDialogRet = xDialog->execute();
2021 if( RET_OK == nDialogRet )
2022 {
2023 //get some parameters from the dialog
2024 bool bToSimplified = xDialog->getIsDirectionToSimplified();
2025 bool bCommonTerms = xDialog->getIsTranslateCommonTerms();
2026
2027 //execute translation
2028 LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
2029 LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
2030 sal_Int32 nOptions = !bCommonTerms ? i18n::TextConversionOption::CHARACTER_BY_CHARACTER : 0;
2031
2032 vcl::Font aTargetFont = OutputDevice::GetDefaultFont(
2033 DefaultFontType::CJK_SPREADSHEET,
2034 eTargetLang, GetDefaultFontFlags::OnlyOne );
2035 ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
2036 eSourceLang, eTargetLang, std::move(aTargetFont), nOptions, false );
2037 pTabViewShell->DoSheetConversion( aConvParam );
2038 }
2039 }
2040 break;
2041
2042 case SID_CONVERT_FORMULA_TO_VALUE:
2043 {
2044 pTabViewShell->ConvertFormulaToValue();
2045 }
2046 break;
2047 case SID_THESAURUS:
2048 pTabViewShell->DoThesaurus();
2049 break;
2050
2051 case SID_TOGGLE_REL:
2052 pTabViewShell->DoRefConversion();
2053 break;
2054
2055 case SID_DEC_INDENT:
2056 pTabViewShell->ChangeIndent( false );
2057 break;
2058 case SID_INC_INDENT:
2059 pTabViewShell->ChangeIndent( true );
2060 break;
2061
2062 case FID_USE_NAME:
2063 {
2064 CreateNameFlags nFlags = pTabViewShell->GetCreateNameFlags();
2065
2066 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2067
2068 ScopedVclPtr<AbstractScNameCreateDlg> pDlg(pFact->CreateScNameCreateDlg(pTabViewShell->GetFrameWeld(), nFlags));
2069
2070 if( pDlg->Execute() )
2071 {
2072 pTabViewShell->CreateNames(pDlg->GetFlags());
2073 rReq.Done();
2074 }
2075 }
2076 break;
2077
2078 case SID_CONSOLIDATE:
2079 {
2080 const ScConsolidateItem* pItem;
2081 if ( pReqArgs && (pItem =
2082 pReqArgs->GetItemIfSet( SCITEM_CONSOLIDATEDATA )) )
2083 {
2084 const ScConsolidateParam& rParam = pItem->GetData();
2085
2086 pTabViewShell->Consolidate( rParam );
2087 GetViewData().GetDocument().SetConsolidateDlgData( std::unique_ptr<ScConsolidateParam>(new ScConsolidateParam(rParam)) );
2088
2089 rReq.Done();
2090 }
2091 #if HAVE_FEATURE_SCRIPTING
2092 else if (rReq.IsAPI())
2093 SbxBase::SetError(ERRCODE_BASIC_BAD_PARAMETER);
2094 #endif
2095 }
2096 break;
2097
2098 case SID_INS_FUNCTION:
2099 {
2100 const SfxPoolItem* pFunction;
2101 const SfxPoolItem* pCategory;
2102 const SfxPoolItem* pFunctionId;
2103 OUString aFunction;
2104 sal_Int16 nCategory = -1;
2105 OUString aFunctionId;
2106
2107 bool bFuncHasCategoryOrId = false;
2108 if (pReqArgs && pReqArgs->HasItem(FN_PARAM_1, &pFunction)
2109 && pReqArgs->HasItem(FN_PARAM_2, &pCategory)) // -1 when aFunctionId not empty
2110 {
2111 aFunction = static_cast<const SfxStringItem*>(pFunction)->GetValue();
2112 nCategory = static_cast<const SfxInt16Item*>(pCategory)->GetValue();
2113
2114 if (nCategory == -1 && pReqArgs->HasItem(FN_PARAM_3, &pFunctionId))
2115 aFunctionId = static_cast<const SfxStringItem*>(pFunctionId)->GetValue();
2116
2117 bFuncHasCategoryOrId = nCategory != -1 || !aFunctionId.isEmpty();
2118 }
2119
2120 if (bFuncHasCategoryOrId)
2121 {
2122 ScInputHandler* pHdl = pScMod->GetInputHdl(pTabViewShell);
2123 OUString aString = aFunction;
2124 if (!pScMod->IsEditMode())
2125 {
2126 pScMod->SetInputMode(SC_INPUT_TABLE);
2127 aString = "=" + aFunction;
2128 if (pHdl)
2129 pHdl->ClearText();
2130 }
2131
2132 const ScFuncDesc* pDesc;
2133 if (nCategory == -1)
2134 pDesc = weld::fromId<const ScFuncDesc*>(aFunctionId);
2135 else
2136 {
2137 ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
2138 const CharClass* pCharClass
2139 = (ScGlobal::GetStarCalcFunctionList()->IsEnglishFunctionNames()
2140 ? ScCompiler::GetCharClassEnglish()
2141 : ScCompiler::GetCharClassLocalized());
2142
2143 pDesc = pFuncMgr->First(nCategory);
2144 while (
2145 pDesc
2146 && !pCharClass->uppercase(pDesc->getFunctionName()).equals(aFunction))
2147 {
2148 pDesc = pFuncMgr->Next();
2149 }
2150 }
2151 if (!pDesc)
2152 {
2153 rReq.Ignore();
2154 break;
2155 }
2156
2157 OUStringBuffer aArgStr;
2158 OUString aFirstArgStr;
2159 sal_uInt16 nArgs = pDesc->nArgCount;
2160 if (nArgs > 0)
2161 {
2162 // NOTE: Theoretically the first parameter could have the
2163 // suppress flag as well, but practically it doesn't.
2164 aFirstArgStr = pDesc->maDefArgNames[0];
2165 aFirstArgStr = comphelper::string::strip(aFirstArgStr, ' ');
2166 aFirstArgStr = aFirstArgStr.replaceAll(" ", "_");
2167 aArgStr = aFirstArgStr;
2168 if (nArgs != VAR_ARGS && nArgs != PAIRED_VAR_ARGS)
2169 { // no VarArgs or Fix plus VarArgs, but not VarArgs only
2170 sal_uInt16 nFix;
2171 if (nArgs >= PAIRED_VAR_ARGS)
2172 nFix = nArgs - PAIRED_VAR_ARGS + 2;
2173 else if (nArgs >= VAR_ARGS)
2174 nFix = nArgs - VAR_ARGS + 1;
2175 else
2176 nFix = nArgs;
2177 for (sal_uInt16 nArg = 1;
2178 nArg < nFix && !pDesc->pDefArgFlags[nArg].bOptional; nArg++)
2179 {
2180 aArgStr.append("; ");
2181 OUString sTmp = pDesc->maDefArgNames[nArg];
2182 sTmp = comphelper::string::strip(sTmp, ' ');
2183 sTmp = sTmp.replaceAll(" ", "_");
2184 aArgStr.append(sTmp);
2185 }
2186 }
2187 }
2188
2189 if (pHdl)
2190 {
2191 if (pHdl->GetEditString().isEmpty())
2192 aString = "=" + aFunction;
2193 EditView* pEdView = pHdl->GetActiveView();
2194 if (pEdView != nullptr)
2195 {
2196 if (nArgs > 0)
2197 {
2198 pHdl->InsertFunction(aString);
2199 pEdView->InsertText(aArgStr.makeStringAndClear(), true);
2200 ESelection aESel = pEdView->GetSelection();
2201 aESel.end.nIndex = aESel.start.nIndex + aFirstArgStr.getLength();
2202 pEdView->SetSelection(aESel);
2203 pHdl->DataChanged();
2204 }
2205 else
2206 {
2207 aString += "()";
2208 pEdView->InsertText(aString);
2209 pHdl->DataChanged();
2210 }
2211 }
2212 }
2213 rReq.Ignore();
2214 break;
2215 }
2216
2217 const SfxBoolItem* pOkItem = static_cast<const SfxBoolItem*>(&pReqArgs->Get( SID_DLG_RETOK ));
2218
2219 if ( pOkItem->GetValue() ) // OK
2220 {
2221 OUString aFormula;
2222 const SfxStringItem* pSItem = &pReqArgs->Get( SCITEM_STRING );
2223 const SfxBoolItem* pMatrixItem = static_cast<const SfxBoolItem*>(&pReqArgs->Get( SID_DLG_MATRIX ));
2224
2225 aFormula += pSItem->GetValue();
2226 pScMod->ActivateInputWindow( &aFormula, pMatrixItem->GetValue() );
2227 }
2228 else // CANCEL
2229 {
2230 pScMod->ActivateInputWindow();
2231 }
2232 rReq.Ignore(); // only SID_ENTER_STRING is recorded
2233 }
2234 break;
2235
2236 case FID_DEFINE_NAME:
2237 case FID_DEFINE_CURRENT_NAME:
2238 if ( pReqArgs )
2239 {
2240 const SfxPoolItem* pItem;
2241 OUString aName, aSymbol, aAttrib;
2242
2243 if( pReqArgs->HasItem( FID_DEFINE_NAME, &pItem ) )
2244 aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
2245
2246 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
2247 aSymbol = static_cast<const SfxStringItem*>(pItem)->GetValue();
2248
2249 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
2250 aAttrib = static_cast<const SfxStringItem*>(pItem)->GetValue();
2251
2252 if ( !aName.isEmpty() && !aSymbol.isEmpty() )
2253 {
2254 if (pTabViewShell->InsertName( aName, aSymbol, aAttrib ))
2255 rReq.Done();
2256 #if HAVE_FEATURE_SCRIPTING
2257 else
2258 SbxBase::SetError( ERRCODE_BASIC_BAD_PARAMETER ); // Basic-error
2259 #endif
2260 }
2261 }
2262 else
2263 {
2264 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
2265 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
2266 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
2267
2268 pScMod->SetRefDialog( nId, pWnd == nullptr );
2269 }
2270 break;
2271 case FID_ADD_NAME:
2272 {
2273 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
2274 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
2275 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
2276
2277 pScMod->SetRefDialog( nId, pWnd == nullptr );
2278 }
2279 break;
2280
2281 case SID_OPENDLG_CONDFRMT:
2282 case SID_OPENDLG_CURRENTCONDFRMT:
2283 case SID_OPENDLG_COLORSCALE:
2284 case SID_OPENDLG_DATABAR:
2285 case SID_OPENDLG_ICONSET:
2286 case SID_OPENDLG_CONDDATE:
2287 {
2288 sal_uInt32 nIndex = sal_uInt32(-1);
2289 bool bManaged = false;
2290
2291 // get the current DialogData
2292 const std::shared_ptr<ScCondFormatDlgData>& rDlgData(pTabViewShell->getScCondFormatDlgData());
2293 if (rDlgData)
2294 {
2295 nIndex = rDlgData->GetIndex();
2296 bManaged = true;
2297 }
2298
2299 // Check if the Conditional Manager Dialog is editing or adding
2300 // conditional format item.
2301 if ( bManaged )
2302 {
2303 sal_uInt16 nId = ScCondFormatDlgWrapper::GetChildWindowId();
2304 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
2305 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
2306
2307 pScMod->SetRefDialog( nId, pWnd == nullptr );
2308 break;
2309 }
2310
2311 ScRangeList aRangeList;
2312 ScViewData& rData = GetViewData();
2313 rData.GetMarkData().FillRangeListWithMarks(&aRangeList, false);
2314
2315 ScDocument& rDoc = GetViewData().GetDocument();
2316 if(rDoc.IsTabProtected(rData.GetTabNo()))
2317 {
2318 pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
2319 break;
2320 }
2321
2322 ScAddress aPos(rData.GetCurX(), rData.GetCurY(), rData.GetTabNo());
2323 if(aRangeList.empty())
2324 {
2325 aRangeList.push_back(ScRange(aPos));
2326 }
2327
2328 // try to find an existing conditional format
2329 const ScPatternAttr* pPattern = rDoc.GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
2330 ScConditionalFormatList* pList = rDoc.GetCondFormList(aPos.Tab());
2331 bool bContainsCondFormat = false;
2332 bool bCondFormatDlg = false;
2333 for (auto nKey : pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData())
2334 {
2335 // check if at least one existing conditional format has the same range
2336 const ScConditionalFormat* pCondFormat = pList->GetFormat(nKey);
2337 if(!pCondFormat)
2338 continue;
2339
2340 bContainsCondFormat = true; // found at least one format
2341 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
2342 if(rCondFormatRange == aRangeList)
2343 {
2344 // found a matching range, edit this conditional format
2345 bCondFormatDlg = true;
2346 nIndex = pCondFormat->GetKey();
2347 break;
2348 }
2349 }
2350
2351 // do we have a parameter with the conditional formatting type?
2352 const SfxInt16Item* pParam = rReq.GetArg<SfxInt16Item>(FN_PARAM_1);
2353 if (pParam)
2354 {
2355 auto pFormat = std::make_unique<ScConditionalFormat>(0, rDoc);
2356 pFormat->SetRange(aRangeList);
2357
2358 if (nSlot == SID_OPENDLG_ICONSET)
2359 {
2360 ScIconSetType eIconSetType = limit_cast<ScIconSetType>(pParam->GetValue(), IconSet_3Arrows, IconSet_5Boxes);
2361 const int nSteps = ScIconSetFormat::getIconSetElements(eIconSetType);
2362
2363 ScIconSetFormat* pEntry = new ScIconSetFormat(rDoc);
2364 ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData(eIconSetType);
2365
2366 pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(0, COL_RED, COLORSCALE_PERCENT));
2367 pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(100. / nSteps), COL_BROWN, COLORSCALE_PERCENT));
2368 pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(200. / nSteps), COL_YELLOW, COLORSCALE_PERCENT));
2369 if (nSteps > 3)
2370 pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(300. / nSteps), COL_WHITE, COLORSCALE_PERCENT));
2371 if (nSteps > 4)
2372 pIconSetFormatData->m_Entries.emplace_back(new ScColorScaleEntry(round(400. / nSteps), COL_GREEN, COLORSCALE_PERCENT));
2373
2374 pEntry->SetIconSetData(pIconSetFormatData);
2375 pFormat->AddEntry(pEntry);
2376 }
2377 else if (nSlot == SID_OPENDLG_COLORSCALE)
2378 {
2379 typedef std::tuple<double, Color, ScColorScaleEntryType> ScaleEntry;
2380 static std::vector<std::vector<ScaleEntry>> aScaleThemes =
2381 {
2382 {
2383 { 0, Color(0xF8696B), COLORSCALE_MIN },
2384 { 0, Color(0x63BE7B), COLORSCALE_MAX },
2385 { 50, Color(0xFFEB84), COLORSCALE_PERCENTILE }
2386 },
2387 {
2388 { 0, Color(0x63BE7B), COLORSCALE_MIN },
2389 { 0, Color(0xF8696B), COLORSCALE_MAX },
2390 { 50, Color(0xFFEB84), COLORSCALE_PERCENTILE }
2391 },
2392 {
2393 { 0, Color(0xF8696B), COLORSCALE_MIN },
2394 { 0, Color(0x63BE7B), COLORSCALE_MAX },
2395 { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE }
2396 },
2397 {
2398 { 0, Color(0x63BE7B), COLORSCALE_MIN },
2399 { 0, Color(0xF8696B), COLORSCALE_MAX },
2400 { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE }
2401 },
2402 {
2403 { 0, Color(0xF8696B), COLORSCALE_MIN },
2404 { 0, Color(0x5A8AC6), COLORSCALE_MAX },
2405 { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE }
2406 },
2407 {
2408 { 0, Color(0x5A8AC6), COLORSCALE_MIN },
2409 { 0, Color(0xF8696B), COLORSCALE_MAX },
2410 { 50, Color(0xFCFCFF), COLORSCALE_PERCENTILE }
2411 },
2412 {
2413 { 0, Color(0xF8696B), COLORSCALE_MIN },
2414 { 0, Color(0xFCFCFF), COLORSCALE_MAX }
2415 },
2416 {
2417 { 0, Color(0xFCFCFF), COLORSCALE_MIN },
2418 { 0, Color(0xF8696B), COLORSCALE_MAX }
2419 },
2420 {
2421 { 0, Color(0x63BE7B), COLORSCALE_MIN },
2422 { 0, Color(0xFCFCFF), COLORSCALE_MAX }
2423 },
2424 {
2425 { 0, Color(0xFCFCFF), COLORSCALE_MIN },
2426 { 0, Color(0x63BE7B), COLORSCALE_MAX }
2427 },
2428 {
2429 { 0, Color(0x63BE7B), COLORSCALE_MIN },
2430 { 0, Color(0xFFEF9C), COLORSCALE_MAX }
2431 },
2432 {
2433 { 0, Color(0xFFEF9C), COLORSCALE_MIN },
2434 { 0, Color(0x63BE7B), COLORSCALE_MAX }
2435 }
2436 };
2437
2438 sal_uInt16 nTheme = pParam->GetValue();
2439 if (nTheme < aScaleThemes.size())
2440 {
2441 ScColorScaleFormat* pFormatEntry = new ScColorScaleFormat(rDoc);
2442
2443 auto& aTheme = aScaleThemes[nTheme];
2444
2445 ScColorScaleEntry* pMin = new ScColorScaleEntry(std::get<0>(aTheme[0]), std::get<1>(aTheme[0]), std::get<2>(aTheme[0]));
2446 ScColorScaleEntry* pMax = new ScColorScaleEntry(std::get<0>(aTheme[1]), std::get<1>(aTheme[1]), std::get<2>(aTheme[1]));
2447
2448 pFormatEntry->AddEntry(pMin);
2449
2450 // COLORSCALE_PERCENTILE has to be in the middle
2451 if (aTheme.size() > 2)
2452 {
2453 ScColorScaleEntry* pPer = new ScColorScaleEntry(std::get<0>(aTheme[2]), std::get<1>(aTheme[2]), std::get<2>(aTheme[2]));
2454 pFormatEntry->AddEntry(pPer);
2455 }
2456
2457 pFormatEntry->AddEntry(pMax);
2458
2459 pFormat->AddEntry(pFormatEntry);
2460 }
2461
2462 }
2463 else if (nSlot == SID_OPENDLG_DATABAR)
2464 {
2465 typedef std::tuple<Color, bool> DatabarEntry;
2466 static std::vector<DatabarEntry> aDatabarThemes =
2467 {
2468 { Color(0x638EC6), true },
2469 { Color(0x63C384), true },
2470 { Color(0xFF555A), true },
2471 { Color(0xFFB628), true },
2472 { Color(0x008AEF), true },
2473 { Color(0xD6007B), true },
2474 { Color(0x638EC6), false },
2475 { Color(0x63C384), false },
2476 { Color(0xFF555A), false },
2477 { Color(0xFFB628), false },
2478 { Color(0x008AEF), false },
2479 { Color(0xD6007B), false }
2480 };
2481
2482 sal_uInt16 nTheme = pParam->GetValue();
2483 if (nTheme < aDatabarThemes.size())
2484 {
2485 ScDataBarFormat* pFormatEntry = new ScDataBarFormat(rDoc);
2486
2487 auto& aTheme = aDatabarThemes[nTheme];
2488
2489 ScDataBarFormatData* pData = new ScDataBarFormatData();
2490 pData->maPositiveColor = std::get<0>(aTheme);
2491 pData->mbGradient = std::get<1>(aTheme);
2492 pData->mxNegativeColor = Color(0xFF0000);
2493 pData->mpLowerLimit.reset(new ScColorScaleEntry(0, 0, COLORSCALE_AUTO));
2494 pData->mpUpperLimit.reset(new ScColorScaleEntry(0, 0, COLORSCALE_AUTO));
2495
2496 pFormatEntry->SetDataBarData(pData);
2497
2498 pFormat->AddEntry(pFormatEntry);
2499 }
2500 }
2501
2502 // use the new conditional formatting
2503 GetViewData().GetDocShell().GetDocFunc().ReplaceConditionalFormat(nIndex, std::move(pFormat), aPos.Tab(), aRangeList);
2504
2505 break;
2506 }
2507
2508 // if not found a conditional format ask whether we should edit one of the existing
2509 // or should create a new overlapping conditional format
2510 if (bContainsCondFormat && !bCondFormatDlg)
2511 {
2512 std::shared_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
2513 VclMessageType::Question, VclButtonsType::YesNo,
2514 ScResId(STR_EDIT_EXISTING_COND_FORMATS), pTabViewShell));
2515 xQueryBox->set_default_response(RET_YES);
2516 xQueryBox->runAsync(xQueryBox, [this, nIndex, nSlot, aPos, pTabViewShell] (int nResult) {
2517 sal_uInt32 nNewIndex = nIndex;
2518 bool bNewCondFormatDlg = false;
2519
2520 // use fresh data
2521 ScDocument& rInnerDoc = GetViewData().GetDocument();
2522 const ScPatternAttr* pInnerPattern = rInnerDoc.GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
2523 ScConditionalFormatList* pInnerList = rInnerDoc.GetCondFormList(aPos.Tab());
2524 const ScCondFormatIndexes& rInnerCondFormats = pInnerPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData();
2525 bool bInnerContainsCondFormat = !rInnerCondFormats.empty();
2526
2527 bool bEditExisting = nResult == RET_YES;
2528 if (bEditExisting)
2529 {
2530 // differentiate between ranges where one conditional format is defined
2531 // and several formats are defined
2532 // if we have only one => open the cond format dlg to edit it
2533 // otherwise open the manage cond format dlg
2534 if (rInnerCondFormats.size() == 1)
2535 {
2536 const ScConditionalFormat* pCondFormat = pInnerList->GetFormat(rInnerCondFormats[0]);
2537 assert(pCondFormat);
2538 nNewIndex = pCondFormat->GetKey();
2539 bNewCondFormatDlg = true;
2540 }
2541 else
2542 {
2543 // Queue message to open Conditional Format Manager Dialog.
2544 GetViewData().GetDispatcher().Execute(
2545 SID_OPENDLG_CONDFRMT_MANAGER, SfxCallMode::ASYNCHRON);
2546 return;
2547 }
2548 }
2549 else
2550 {
2551 // define an overlapping conditional format
2552 assert(pInnerList->GetFormat(rInnerCondFormats[0]));
2553 bNewCondFormatDlg = true;
2554 }
2555
2556 HandleConditionalFormat(nNewIndex, bNewCondFormatDlg, bInnerContainsCondFormat,
2557 nSlot, pTabViewShell);
2558 });
2559 }
2560 else
2561 {
2562 HandleConditionalFormat(nIndex, bCondFormatDlg, bContainsCondFormat, nSlot, pTabViewShell);
2563 }
2564 }
2565 break;
2566
2567 case SID_DEFINE_COLROWNAMERANGES:
2568 {
2569
2570 sal_uInt16 nId = ScColRowNameRangesDlgWrapper::GetChildWindowId();
2571 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
2572 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
2573
2574 pScMod->SetRefDialog( nId, pWnd == nullptr );
2575
2576 }
2577 break;
2578
2579 case SID_UPDATECHART:
2580 {
2581 bool bAll = false;
2582
2583 if( pReqArgs )
2584 {
2585 const SfxPoolItem* pItem;
2586
2587 if( pReqArgs->HasItem( SID_UPDATECHART, &pItem ) )
2588 bAll = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2589 }
2590
2591 pTabViewShell->UpdateCharts( bAll );
2592
2593 if( ! rReq.IsAPI() )
2594 {
2595 rReq.AppendItem( SfxBoolItem( SID_UPDATECHART, bAll ) );
2596 rReq.Done();
2597 }
2598 }
2599 break;
2600
2601 case SID_TABOP:
2602 if (pReqArgs)
2603 {
2604 const ScTabOpItem& rItem =
2605 static_cast<const ScTabOpItem&>(
2606 pReqArgs->Get( SID_TABOP ));
2607
2608 pTabViewShell->TabOp( rItem.GetData() );
2609
2610 rReq.Done( *pReqArgs );
2611 }
2612 break;
2613
2614 case SID_SOLVE:
2615 if (pReqArgs)
2616 {
2617 const ScSolveItem& rItem =
2618 pReqArgs->Get( SCITEM_SOLVEDATA );
2619
2620 pTabViewShell->Solve( rItem.GetData() );
2621
2622 rReq.Done( *pReqArgs );
2623 }
2624 break;
2625
2626 case FID_INSERT_NAME:
2627 {
2628 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2629
2630 ScopedVclPtr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg(pTabViewShell->GetFrameWeld(), &GetViewData().GetDocShell()));
2631 switch( pDlg->Execute() )
2632 {
2633 case BTN_PASTE_LIST:
2634 pTabViewShell->InsertNameList();
2635 break;
2636 case BTN_PASTE_NAME:
2637 {
2638 ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
2639 if (pHdl)
2640 {
2641 // "=" in KeyEvent, switches to input-mode
2642 (void)pScMod->InputKeyEvent( KeyEvent('=', vcl::KeyCode()) );
2643
2644 std::vector<OUString> aNames = pDlg->GetSelectedNames();
2645 if (!aNames.empty())
2646 {
2647 OUStringBuffer aBuffer;
2648 for (const auto& rName : aNames)
2649 {
2650 aBuffer.append(rName + " ");
2651 }
2652 pHdl->InsertFunction( aBuffer.makeStringAndClear(), false ); // without "()"
2653 }
2654 }
2655 }
2656 break;
2657 }
2658 }
2659 break;
2660
2661 case SID_RANGE_NOTETEXT:
2662 if (pReqArgs)
2663 {
2664 const SfxStringItem& rTextItem = pReqArgs->Get( SID_RANGE_NOTETEXT );
2665
2666 // always cursor position
2667 ScAddress aPos( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
2668 pTabViewShell->SetNoteText( aPos, rTextItem.GetValue() );
2669 rReq.Done();
2670 }
2671 break;
2672
2673 case SID_INSERT_POSTIT:
2674 case SID_EDIT_POSTIT:
2675 {
2676 const SvxPostItTextItem* pTextItem;
2677 if ( pReqArgs && (pTextItem = pReqArgs->GetItemIfSet( SID_ATTR_POSTIT_TEXT )) )
2678 {
2679 OUString aCellId;
2680 // SID_ATTR_POSTIT_ID only argument for SID_EDIT_POSTIT
2681 if (const SvxPostItIdItem* pCellId = pReqArgs->GetItemIfSet( SID_ATTR_POSTIT_ID ))
2682 aCellId = pCellId->GetValue();
2683
2684 const SvxPostItAuthorItem* pAuthorItem = pReqArgs->GetItem( SID_ATTR_POSTIT_AUTHOR );
2685 const SvxPostItDateItem* pDateItem = pReqArgs->GetItem( SID_ATTR_POSTIT_DATE );
2686
2687 if (!aCellId.isEmpty())
2688 {
2689 SetTabNoAndCursor( GetViewData(), aCellId );
2690 }
2691
2692 ScAddress aPos( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
2693 pTabViewShell->ReplaceNote( aPos, pTextItem->GetValue(),
2694 pAuthorItem ? &pAuthorItem->GetValue() : nullptr,
2695 pDateItem ? &pDateItem->GetValue() : nullptr );
2696 }
2697 else if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledAnnotations())
2698 {
2699 pTabViewShell->EditNote(); // note object to edit
2700 }
2701 rReq.Done();
2702 }
2703 break;
2704
2705 case FID_NOTE_VISIBLE:
2706 {
2707 ScDocument& rDoc = GetViewData().GetDocument();
2708 ScAddress aPos( GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetTabNo() );
2709 if( ScPostIt* pNote = rDoc.GetNote(aPos) )
2710 {
2711 bool bShow;
2712 const SfxPoolItem* pItem;
2713 if ( pReqArgs && (pReqArgs->GetItemState( FID_NOTE_VISIBLE, true, &pItem ) == SfxItemState::SET) )
2714 bShow = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2715 else
2716 bShow = !pNote->IsCaptionShown();
2717
2718 pTabViewShell->ShowNote( bShow );
2719
2720 if (!pReqArgs)
2721 rReq.AppendItem( SfxBoolItem( FID_NOTE_VISIBLE, bShow ) );
2722
2723 rReq.Done();
2724 rBindings.Invalidate( FID_NOTE_VISIBLE );
2725 }
2726 else
2727 rReq.Ignore();
2728 }
2729 break;
2730
2731 case FID_HIDE_NOTE:
2732 case FID_SHOW_NOTE:
2733 {
2734 bool bShowNote = nSlot == FID_SHOW_NOTE;
2735 ScViewData& rData = GetViewData();
2736 ScDocument& rDoc = rData.GetDocument();
2737 ScMarkData& rMark = rData.GetMarkData();
2738
2739 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2740 {
2741 // Check current cell
2742 ScAddress aPos( rData.GetCurX(), rData.GetCurY(), rData.GetTabNo() );
2743 if( rDoc.GetNote(aPos) )
2744 {
2745 rData.GetDocShell().GetDocFunc().ShowNote( aPos, bShowNote );
2746 }
2747 }
2748 else
2749 {
2750 // Check selection range
2751 bool bDone = false;
2752 ScRangeListRef aRangesRef;
2753 rData.GetMultiArea(aRangesRef);
2754 const ScRangeList aRanges = *aRangesRef;
2755
2756 OUString aUndo = ScResId( bShowNote ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
2757 rData.GetDocShell().GetUndoManager()->EnterListAction( aUndo, aUndo, 0, rData.GetViewShell()->GetViewShellId() );
2758
2759 for (auto const& rTab : rMark.GetSelectedTabs())
2760 {
2761 // get notes
2762 std::vector<sc::NoteEntry> aNotes;
2763 rDoc.GetAllNoteEntries(rTab, aNotes);
2764
2765 for (const sc::NoteEntry& rNote : aNotes)
2766 {
2767 // check if note is in our selection range
2768 const ScAddress& rAdr = rNote.maPos;
2769 const ScRange* rRange = aRanges.Find(rAdr);
2770 if (! rRange)
2771 continue;
2772
2773 // check if cell is editable
2774 const SCTAB nRangeTab = rRange->aStart.Tab();
2775 if (rDoc.IsBlockEditable( nRangeTab, rAdr.Col(), rAdr.Row(), rAdr.Col(), rAdr.Row() ))
2776 {
2777 rData.GetDocShell().GetDocFunc().ShowNote( rAdr, bShowNote );
2778 bDone = true;
2779 }
2780 }
2781 }
2782
2783 rData.GetDocShell().GetUndoManager()->LeaveListAction();
2784
2785 if ( bDone )
2786 {
2787 rReq.Done();
2788 rBindings.Invalidate( nSlot );
2789 }
2790 else
2791 rReq.Ignore();
2792 }
2793
2794 }
2795 break;
2796
2797 case FID_SHOW_ALL_NOTES:
2798 case FID_HIDE_ALL_NOTES:
2799 {
2800 bool bShowNote = nSlot == FID_SHOW_ALL_NOTES;
2801 ScViewData& rData = GetViewData();
2802 ScMarkData& rMark = rData.GetMarkData();
2803 ScDocument& rDoc = rData.GetDocument();
2804 std::vector<sc::NoteEntry> aNotes;
2805
2806 OUString aUndo = ScResId( bShowNote ? STR_UNDO_SHOWALLNOTES : STR_UNDO_HIDEALLNOTES );
2807 rData.GetDocShell().GetUndoManager()->EnterListAction( aUndo, aUndo, 0, rData.GetViewShell()->GetViewShellId() );
2808
2809 for (auto const& rTab : rMark.GetSelectedTabs())
2810 {
2811 rDoc.GetAllNoteEntries(rTab, aNotes);
2812 }
2813
2814 for (const sc::NoteEntry& rNote : aNotes)
2815 {
2816 const ScAddress& rAdr = rNote.maPos;
2817 rData.GetDocShell().GetDocFunc().ShowNote( rAdr, bShowNote );
2818 }
2819
2820 rData.GetDocShell().GetUndoManager()->LeaveListAction();
2821 }
2822 break;
2823
2824 case SID_TOGGLE_NOTES:
2825 {
2826 ScViewData& rData = GetViewData();
2827 ScMarkData& rMark = rData.GetMarkData();
2828 ScDocument& rDoc = rData.GetDocument();
2829 ScRangeList aRanges;
2830 std::vector<sc::NoteEntry> aNotes;
2831
2832 for (auto const& rTab : rMark.GetSelectedTabs())
2833 aRanges.push_back(ScRange(0,0,rTab,rDoc.MaxCol(),rDoc.MaxRow(),rTab));
2834
2835 CommentCaptionState eState = rDoc.GetAllNoteCaptionsState( aRanges );
2836 rDoc.GetNotesInRange(aRanges, aNotes);
2837 bool bShowNote = (eState == ALLHIDDEN || eState == MIXED);
2838
2839 OUString aUndo = ScResId( bShowNote ? STR_UNDO_SHOWALLNOTES : STR_UNDO_HIDEALLNOTES );
2840 rData.GetDocShell().GetUndoManager()->EnterListAction( aUndo, aUndo, 0, rData.GetViewShell()->GetViewShellId() );
2841
2842 for(const auto& rNote : aNotes)
2843 {
2844 const ScAddress& rAdr = rNote.maPos;
2845 rData.GetDocShell().GetDocFunc().ShowNote( rAdr, bShowNote );
2846 }
2847
2848 rData.GetDocShell().GetUndoManager()->LeaveListAction();
2849
2850 if (!pReqArgs)
2851 rReq.AppendItem( SfxBoolItem( SID_TOGGLE_NOTES, bShowNote ) );
2852
2853 rReq.Done();
2854 rBindings.Invalidate( SID_TOGGLE_NOTES );
2855 }
2856 break;
2857
2858 case SID_DELETE_NOTE:
2859 {
2860 const SvxPostItIdItem* pIdItem;
2861 // If Id is mentioned, select the appropriate cell first
2862 if ( pReqArgs && (pIdItem = pReqArgs->GetItemIfSet( SID_ATTR_POSTIT_ID )) )
2863 {
2864 const OUString& aCellId = pIdItem->GetValue();
2865 if (!aCellId.isEmpty())
2866 {
2867 SetTabNoAndCursor( GetViewData(), aCellId );
2868 }
2869 }
2870
2871 pTabViewShell->DeleteContents( InsertDeleteFlags::NOTE ); // delete all notes in selection
2872 rReq.Done();
2873 }
2874 break;
2875
2876 case FID_DELETE_ALL_NOTES:
2877 {
2878 ScViewData& rData = GetViewData();
2879 ScMarkData& rMark = rData.GetMarkData();
2880 ScDocument& rDoc = rData.GetDocument();
2881 ScMarkData aNewMark(rDoc.GetSheetLimits());
2882 ScRangeList aRangeList;
2883
2884 for (auto const& rTab : rMark.GetSelectedTabs())
2885 {
2886 aRangeList.push_back(ScRange(0,0,rTab,rDoc.MaxCol(),rDoc.MaxRow(),rTab));
2887 }
2888
2889 aNewMark.MarkFromRangeList( aRangeList, true );
2890 rData.GetDocShell().GetDocFunc().DeleteContents(aNewMark, InsertDeleteFlags::NOTE, true, false );
2891 }
2892 break;
2893
2894 case SID_CHARMAP:
2895 if( pReqArgs != nullptr )
2896 {
2897 OUString aChars, aFontName;
2898 const SfxItemSet *pArgs = rReq.GetArgs();
2899 const SfxPoolItem* pItem = nullptr;
2900 if ( pArgs )
2901 pArgs->GetItemState(SID_CHARMAP, false, &pItem);
2902 if ( pItem )
2903 {
2904 const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( pItem );
2905 if ( pStringItem )
2906 aChars = pStringItem->GetValue();
2907 const SfxStringItem* pFontItem =
2908 pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false);
2909 if ( pFontItem )
2910 aFontName = pFontItem->GetValue();
2911 }
2912
2913 if ( !aChars.isEmpty() )
2914 {
2915 vcl::Font aFont;
2916 pTabViewShell->GetSelectionPattern()->fillFontOnly(aFont, nullptr, nullptr, nullptr,
2917 pTabViewShell->GetSelectionScriptType() );
2918 if ( !aFontName.isEmpty() )
2919 aFont = vcl::Font( aFontName, Size(1,1) );
2920 pTabViewShell->InsertSpecialChar( aChars, aFont );
2921 if( ! rReq.IsAPI() )
2922 rReq.Done();
2923 }
2924 }
2925 else
2926 {
2927 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2928
2929 // font color doesn't matter here
2930 vcl::Font aCurFont;
2931 pTabViewShell->GetSelectionPattern()->fillFontOnly(aCurFont, nullptr, nullptr, nullptr,
2932 pTabViewShell->GetSelectionScriptType());
2933
2934 SfxAllItemSet aSet( GetPool() );
2935 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
2936 aSet.Put( SvxFontItem( aCurFont.GetFamilyTypeMaybeAskConfig(), aCurFont.GetFamilyName(), aCurFont.GetStyleName(), aCurFont.GetPitchMaybeAskConfig(), aCurFont.GetCharSet(), GetPool().GetWhichIDFromSlotID(SID_ATTR_CHAR_FONT) ) );
2937 SfxViewFrame& rViewFrame = pTabViewShell->GetViewFrame();
2938 auto xFrame = rViewFrame.GetFrame().GetFrameInterface();
2939 VclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(pTabViewShell->GetFrameWeld(), aSet, xFrame));
2940 pDlg->StartExecuteAsync(
2941 [pDlg] (sal_Int32 /*nResult*/)->void
2942 {
2943 pDlg->disposeOnce();
2944 }
2945 );
2946 }
2947 break;
2948
2949 case SID_SELECT_SCENARIO:
2950 {
2951 // Testing
2952
2953 if ( pReqArgs )
2954 {
2955 const SfxStringItem& rItem = pReqArgs->Get(SID_SELECT_SCENARIO);
2956 pTabViewShell->UseScenario(rItem.GetValue());
2957 //! why should the return value be valid?!?!
2958 rReq.SetReturnValue(SfxStringItem(SID_SELECT_SCENARIO, rItem.GetValue()));
2959 rReq.Done();
2960 }
2961 }
2962 break;
2963
2964 case SID_HYPERLINK_SETLINK:
2965 if( pReqArgs )
2966 {
2967 const SfxPoolItem* pItem;
2968 if( pReqArgs->HasItem( SID_HYPERLINK_SETLINK, &pItem ) )
2969 {
2970 const SvxHyperlinkItem* pHyper = static_cast<const SvxHyperlinkItem*>(pItem);
2971 const OUString& rName = pHyper->GetName();
2972 const OUString& rURL = pHyper->GetURL();
2973 const OUString& rTarget = pHyper->GetTargetFrame();
2974 sal_uInt16 nType = static_cast<sal_uInt16>(pHyper->GetInsertMode());
2975
2976 pTabViewShell->InsertURL( rName, rURL, rTarget, nType );
2977 rReq.Done();
2978 }
2979 else
2980 rReq.Ignore();
2981 }
2982 break;
2983
2984 case SID_OPENDLG_CONDFRMT_MANAGER:
2985 case SID_OPENDLG_CURRENTCONDFRMT_MANAGER:
2986 {
2987 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2988
2989 ScViewData& rData = GetViewData();
2990 ScDocument& rDoc = rData.GetDocument();
2991
2992 if (rDoc.IsTabProtected(rData.GetTabNo()))
2993 {
2994 pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
2995 break;
2996 }
2997
2998 ScAddress aPos(rData.GetCurX(), rData.GetCurY(), rData.GetTabNo());
2999
3000 ScConditionalFormatList* pList = nullptr;
3001
3002 // get the current DialogData
3003 const std::shared_ptr<ScCondFormatDlgData>& rDlgData(pTabViewShell->getScCondFormatDlgData());
3004 if (rDlgData)
3005 {
3006 pList = rDlgData->GetConditionalFormatList();
3007 }
3008
3009 if (!pList)
3010 pList = rDoc.GetCondFormList( aPos.Tab() );
3011
3012 VclPtr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg(
3013 pTabViewShell->GetFrameWeld(), rDoc, pList));
3014
3015 if (rDlgData)
3016 {
3017 pDlg->SetModified();
3018 // reset the current DialogData, will be reset when needed below
3019 pTabViewShell->setScCondFormatDlgData(nullptr);
3020 }
3021
3022 pDlg->StartExecuteAsync(
3023 [this, pDlg, &rData, pTabViewShell, aPos](sal_Int32 nRet)
3024 {
3025 std::unique_ptr<ScConditionalFormatList> pCondFormatList
3026 = pDlg->GetConditionalFormatList();
3027 if (nRet == RET_OK && pDlg->CondFormatsChanged())
3028 {
3029 rData.GetDocShell().GetDocFunc().SetConditionalFormatList(
3030 pCondFormatList.release(), aPos.Tab());
3031 }
3032 else if (nRet == DLG_RET_ADD)
3033 {
3034 // Put the xml string parameter to initialize the
3035 // Conditional Format Dialog. ( add new ). Provide
3036 // new DialogData
3037 pTabViewShell->setScCondFormatDlgData(
3038 std::make_shared<ScCondFormatDlgData>(
3039 std::shared_ptr<ScConditionalFormatList>(
3040 pCondFormatList.release()),
3041 -1, true));
3042
3043 // Queue message to open Conditional Format Dialog
3044 GetViewData().GetDispatcher().Execute(SID_OPENDLG_CONDFRMT,
3045 SfxCallMode::ASYNCHRON);
3046 }
3047 else if (nRet == DLG_RET_EDIT)
3048 {
3049 ScConditionalFormat* pFormat = pDlg->GetCondFormatSelected();
3050 sal_uInt32 nIndex = pFormat ? pFormat->GetKey() : sal_uInt32(-1);
3051 // Put the xml string parameter to initialize the
3052 // Conditional Format Dialog. ( edit selected conditional format ).
3053 // Provide new DialogData
3054 pTabViewShell->setScCondFormatDlgData(
3055 std::make_shared<ScCondFormatDlgData>(
3056 std::shared_ptr<ScConditionalFormatList>(
3057 pCondFormatList.release()),
3058 nIndex, true));
3059
3060 // Queue message to open Conditional Format Dialog
3061 GetViewData().GetDispatcher().Execute(SID_OPENDLG_CONDFRMT,
3062 SfxCallMode::ASYNCHRON);
3063 }
3064 else
3065 pCondFormatList.reset();
3066
3067 pDlg->disposeOnce();
3068 });
3069 }
3070 break;
3071
3072 case SID_EXTERNAL_SOURCE:
3073 {
3074 const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>(SID_FILE_NAME);
3075 const SfxStringItem* pSource = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
3076 if ( pFile && pSource )
3077 {
3078 OUString aFile;
3079 OUString aFilter;
3080 OUString aOptions;
3081 OUString aSource;
3082 sal_Int32 nRefreshDelaySeconds=0;
3083
3084 aFile = pFile->GetValue();
3085 aSource = pSource->GetValue();
3086 const SfxStringItem* pFilter = rReq.GetArg<SfxStringItem>(SID_FILTER_NAME);
3087 if ( pFilter )
3088 aFilter = pFilter->GetValue();
3089 const SfxStringItem* pOptions = rReq.GetArg<SfxStringItem>(SID_FILE_FILTEROPTIONS);
3090 if ( pOptions )
3091 aOptions = pOptions->GetValue();
3092 const SfxUInt32Item* pRefresh = rReq.GetArg<SfxUInt32Item>(FN_PARAM_2);
3093 if ( pRefresh )
3094 nRefreshDelaySeconds = pRefresh->GetValue();
3095
3096 ExecuteExternalSource( aFile, aFilter, aOptions, aSource, nRefreshDelaySeconds, rReq );
3097 }
3098 else
3099 {
3100 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
3101
3102 pImpl->m_pLinkedDlg.disposeAndClear();
3103 pImpl->m_pLinkedDlg =
3104 pFact->CreateScLinkedAreaDlg(pTabViewShell->GetFrameWeld());
3105 delete pImpl->m_pRequest;
3106 pImpl->m_pRequest = new SfxRequest( rReq );
3107 OUString sFile, sFilter, sOptions, sSource;
3108 sal_Int32 nRefreshDelaySeconds = 0;
3109 if (pImpl->m_pLinkedDlg->Execute() == RET_OK)
3110 {
3111 sFile = pImpl->m_pLinkedDlg->GetURL();
3112 sFilter = pImpl->m_pLinkedDlg->GetFilter();
3113 sOptions = pImpl->m_pLinkedDlg->GetOptions();
3114 sSource = pImpl->m_pLinkedDlg->GetSource();
3115 nRefreshDelaySeconds = pImpl->m_pLinkedDlg->GetRefreshDelaySeconds();
3116 if ( !sFile.isEmpty() )
3117 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, sFile ) );
3118 if ( !sFilter.isEmpty() )
3119 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILTER_NAME, sFilter ) );
3120 if ( !sOptions.isEmpty() )
3121 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
3122 if ( !sSource.isEmpty() )
3123 pImpl->m_pRequest->AppendItem( SfxStringItem( FN_PARAM_1, sSource ) );
3124 if ( nRefreshDelaySeconds )
3125 pImpl->m_pRequest->AppendItem( SfxUInt32Item( FN_PARAM_2, nRefreshDelaySeconds ) );
3126 }
3127
3128 ExecuteExternalSource( sFile, sFilter, sOptions, sSource, nRefreshDelaySeconds, *(pImpl->m_pRequest) );
3129 }
3130 }
3131 break;
3132
3133 case SID_AUTO_SUM:
3134 {
3135 const SfxItemSet *pArgs = rReq.GetArgs();
3136 const OUString sFunction = pArgs ?
3137 static_cast<const SfxStringItem&>( pArgs->Get( SID_AUTO_SUM ) ).GetValue()
3138 : u""_ustr;
3139
3140 OpCode eFunction = ocSum;
3141 if (sFunction == "average")
3142 eFunction = ocAverage;
3143 else if (sFunction == "count")
3144 eFunction = ocCount;
3145 else if (sFunction == "min")
3146 eFunction = ocMin;
3147 if (sFunction == "max")
3148 eFunction = ocMax;
3149
3150 bool bSubTotal = false;
3151 bool bRangeFinder = false;
3152 const OUString aFormula = pTabViewShell->DoAutoSum( bRangeFinder, bSubTotal , eFunction );
3153 if ( !aFormula.isEmpty() )
3154 {
3155 const sal_Int32 nPar = aFormula.indexOf( '(' );
3156 const sal_Int32 nLen = aFormula.getLength();
3157 ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
3158
3159 if ( pHdl && nPar != -1 )
3160 {
3161 if ( !pScMod->IsEditMode() )
3162 {
3163 pScMod->SetInputMode( SC_INPUT_TABLE );
3164 }
3165
3166 EditView *pEditView=pHdl->GetActiveView();
3167 if ( pEditView )
3168 {
3169 ESelection aTextSel = pEditView->GetSelection();
3170 aTextSel.start.nIndex = 0;
3171 aTextSel.end.nIndex = EE_TEXTPOS_MAX;
3172 pHdl->DataChanging();
3173 pEditView->SetSelection(aTextSel);
3174 pEditView->InsertText(aFormula);
3175 pEditView->SetSelection( bRangeFinder ? ESelection( 0, nPar + ( bSubTotal ? 3 : 1 ), 0, nLen - 1 ) : ESelection( 0, nLen - 1, 0, nLen - 1 ) );
3176 pHdl->DataChanged();
3177
3178 if ( bRangeFinder )
3179 {
3180 pHdl->InitRangeFinder( aFormula );
3181 }
3182 }
3183 }
3184 }
3185 }
3186 break;
3187
3188 case SID_SELECT_UNPROTECTED_CELLS:
3189 {
3190 ScViewData& rData = GetViewData();
3191 SCTAB aTab = rData.GetTabNo();
3192 ScMarkData& rMark = rData.GetMarkData();
3193 ScDocument& rDoc = rData.GetDocument();
3194 ScRangeList rRangeList;
3195
3196 rDoc.GetUnprotectedCells(rRangeList, aTab);
3197 rMark.MarkFromRangeList(rRangeList, true);
3198 pTabViewShell->SetMarkData(rMark);
3199 }
3200 break;
3201
3202 case SID_SELECT_VISIBLE_ROWS:
3203 {
3204 ScViewData& rData = GetViewData();
3205 ScMarkData& rMark = rData.GetMarkData();
3206 ScDocument& rDoc = rData.GetDocument();
3207
3208 rMark.MarkToMulti();
3209
3210 const ScRange& aMultiArea = rMark.GetMultiMarkArea();
3211 SCCOL nStartCol = aMultiArea.aStart.Col();
3212 SCROW nStartRow = aMultiArea.aStart.Row();
3213 SCCOL nEndCol = aMultiArea.aEnd.Col();
3214 SCROW nEndRow = aMultiArea.aEnd.Row();
3215
3216 bool bChanged = false;
3217 for (const SCTAB& nTab : rMark)
3218 {
3219 for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
3220 {
3221 SCROW nLastRow = nRow;
3222 if (rDoc.RowHidden(nRow, nTab, nullptr, &nLastRow))
3223 {
3224 rMark.SetMultiMarkArea(
3225 ScRange(nStartCol, nRow, nTab, nEndCol, nLastRow, nTab), false);
3226 bChanged = true;
3227 nRow = nLastRow;
3228 }
3229 }
3230 }
3231
3232 if (bChanged && !rMark.HasAnyMultiMarks())
3233 rMark.ResetMark();
3234
3235 rMark.MarkToSimple();
3236
3237 pTabViewShell->SelectionChanged();
3238 }
3239 break;
3240
3241 case SID_SELECT_VISIBLE_COLUMNS:
3242 {
3243 ScViewData& rData = GetViewData();
3244 ScMarkData& rMark = rData.GetMarkData();
3245 ScDocument& rDoc = rData.GetDocument();
3246
3247 rMark.MarkToMulti();
3248
3249 const ScRange& aMultiArea = rMark.GetMultiMarkArea();
3250 SCCOL nStartCol = aMultiArea.aStart.Col();
3251 SCROW nStartRow = aMultiArea.aStart.Row();
3252 SCCOL nEndCol = aMultiArea.aEnd.Col();
3253 SCROW nEndRow = aMultiArea.aEnd.Row();
3254
3255 bool bChanged = false;
3256 for (const SCTAB& nTab : rMark)
3257 {
3258 for (SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol)
3259 {
3260 SCCOL nLastCol = nCol;
3261 if (rDoc.ColHidden(nCol, nTab, nullptr, &nLastCol))
3262 {
3263 rMark.SetMultiMarkArea(
3264 ScRange(nCol, nStartRow, nTab, nLastCol, nEndRow, nTab), false);
3265 bChanged = true;
3266 nCol = nLastCol;
3267 }
3268 }
3269 }
3270
3271 if (bChanged && !rMark.HasAnyMultiMarks())
3272 rMark.ResetMark();
3273
3274 rMark.MarkToSimple();
3275
3276 pTabViewShell->SelectionChanged();
3277 }
3278 break;
3279
3280 case SID_CURRENT_FORMULA_RANGE:
3281 {
3282 const SfxInt32Item* param1 = rReq.GetArg<SfxInt32Item>(FN_PARAM_1);
3283 SCCOL colStart = param1 ? param1->GetValue() : 0;
3284
3285 const SfxInt32Item* param2 = rReq.GetArg<SfxInt32Item>(FN_PARAM_2);
3286 SCROW rowStart = param2 ? param2->GetValue() : 0;
3287
3288 const SfxInt32Item* param3 = rReq.GetArg<SfxInt32Item>(FN_PARAM_3);
3289 SCCOL colEnd = param3 ? param3->GetValue() : 0;
3290
3291 const SfxInt32Item* param4 = rReq.GetArg<SfxInt32Item>(FN_PARAM_4);
3292 SCROW rowEnd = param4 ? param4->GetValue() : 0;
3293
3294 const SfxInt32Item* param5 = rReq.GetArg<SfxInt32Item>(FN_PARAM_5);
3295 SCROW table = param5 ? param5->GetValue() : 0;
3296
3297 ScInputHandler* pInputHdl = pScMod->GetInputHdl();
3298
3299 if (param3 && param4 && pInputHdl)
3300 {
3301 ScViewData& rData = pTabViewShell->GetViewData();
3302 ScTabView* pTabView = rData.GetView();
3303
3304 if (param1 && param2)
3305 rData.SetRefStart(colStart, rowStart, table);
3306
3307 pTabView->UpdateRef( colEnd, rowEnd, table ); // setup the end & refresh formula
3308
3309 ScRange aRef(
3310 colStart, rowStart, rData.GetRefStartZ(),
3311 colEnd, rowEnd, rData.GetRefEndZ() );
3312 pScMod->SetReference( aRef, rData.GetDocument(), &rData.GetMarkData() );
3313
3314 pInputHdl->UpdateLokReferenceMarks();
3315 }
3316 }
3317 break;
3318
3319 case SID_COPY_HYPERLINK_LOCATION:
3320 {
3321 ScViewData& rData = GetViewData();
3322 ScGridWindow* pWindow = rData.GetActiveWin();
3323 const SfxInt32Item* pPosX = rReq.GetArg<SfxInt32Item>(FN_PARAM_1);
3324 const SfxInt32Item* pPosY = rReq.GetArg<SfxInt32Item>(FN_PARAM_2);
3325 if (pWindow && pPosX && pPosY)
3326 {
3327 const Point aPoint(pPosX->GetValue() * rData.GetPPTX(),
3328 pPosY->GetValue() * rData.GetPPTY());
3329 OUString aUrl;
3330 if (pWindow->GetEditUrl(aPoint, nullptr, &aUrl))
3331 {
3332 uno::Reference<datatransfer::clipboard::XClipboard> xClipboard
3333 = pWindow->GetClipboard();
3334 vcl::unohelper::TextDataObject::CopyStringTo(aUrl, xClipboard,
3335 rData.GetViewShell());
3336 rReq.Done();
3337 }
3338 }
3339 }
3340 break;
3341
3342 case SID_EDIT_HYPERLINK:
3343 case SID_REMOVE_HYPERLINK:
3344 {
3345 ScViewData& rData = GetViewData();
3346 ScGridWindow* pWindow = rData.GetActiveWin();
3347 const SfxInt32Item* pPosX = rReq.GetArg<SfxInt32Item>(FN_PARAM_1);
3348 const SfxInt32Item* pPosY = rReq.GetArg<SfxInt32Item>(FN_PARAM_2);
3349 if (pWindow && pPosX && pPosY)
3350 {
3351 const Point aPoint(pPosX->GetValue() * rData.GetPPTX(),
3352 pPosY->GetValue() * rData.GetPPTY());
3353 SCCOL nPosX;
3354 SCROW nPosY;
3355 ScSplitPos eWhich = rData.GetActivePart();
3356 rData.GetPosFromPixel(aPoint.X(), aPoint.Y(), eWhich, nPosX, nPosY);
3357 if (pWindow->GetEditUrl(aPoint, nullptr, nullptr, nullptr, &nPosX))
3358 {
3359 pTabViewShell->SetCursor(nPosX, nPosY);
3360 pTabViewShell->UpdateInputHandler();
3361 pScMod->SetInputMode(SC_INPUT_TABLE);
3362 ScInputHandler* pHdl = pScMod->GetInputHdl(pTabViewShell);
3363 if (rData.HasEditView(eWhich) && pHdl)
3364 {
3365 // Set text cursor where clicked
3366 EditView* pEditView = rData.GetEditView(eWhich);
3367 MouseEvent aEditEvt(aPoint, 1, MouseEventModifiers::SYNTHETIC,
3368 MOUSE_LEFT, 0);
3369 pEditView->MouseButtonDown(aEditEvt);
3370 pEditView->MouseButtonUp(aEditEvt);
3371 if (nSlot == SID_REMOVE_HYPERLINK)
3372 {
3373 pHdl->DataChanging();
3374 URLFieldHelper::RemoveURLField(*pEditView);
3375 pHdl->DataChanged();
3376 pHdl->EnterHandler();
3377 }
3378 else
3379 {
3380 pEditView->SelectFieldAtCursor();
3381 rData.GetViewShell()->GetViewFrame().GetDispatcher()->Execute(
3382 SID_HYPERLINK_DIALOG);
3383 }
3384 rReq.Done();
3385 }
3386 }
3387 }
3388 }
3389 break;
3390
3391 default:
3392 OSL_FAIL("incorrect slot in ExecuteEdit");
3393 break;
3394 }
3395 }
3396
ExecuteTrans(SfxRequest & rReq)3397 void ScCellShell::ExecuteTrans( SfxRequest& rReq )
3398 {
3399 TransliterationFlags nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
3400 if ( nType != TransliterationFlags::NONE )
3401 {
3402 GetViewData().GetView()->TransliterateText( nType );
3403 rReq.Done();
3404 }
3405 }
3406
ExecuteRotateTrans(const SfxRequest & rReq)3407 void ScCellShell::ExecuteRotateTrans( const SfxRequest& rReq )
3408 {
3409 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
3410 GetViewData().GetView()->TransliterateText( m_aRotateCase.getNextMode() );
3411 }
3412
ExecuteExternalSource(const OUString & _rFile,const OUString & _rFilter,const OUString & _rOptions,const OUString & _rSource,sal_Int32 _nRefreshDelaySeconds,SfxRequest & _rRequest)3413 void ScCellShell::ExecuteExternalSource(
3414 const OUString& _rFile, const OUString& _rFilter, const OUString& _rOptions,
3415 const OUString& _rSource, sal_Int32 _nRefreshDelaySeconds, SfxRequest& _rRequest )
3416 {
3417 if ( !_rFile.isEmpty() && !_rSource.isEmpty() ) // filter may be empty
3418 {
3419 ScRange aLinkRange;
3420 bool bMove = false;
3421
3422 ScViewData& rData = GetViewData();
3423 ScMarkData& rMark = rData.GetMarkData();
3424 rMark.MarkToSimple();
3425 if ( rMark.IsMarked() )
3426 {
3427 aLinkRange = rMark.GetMarkArea();
3428 bMove = true; // insert/delete cells to fit range
3429 }
3430 else
3431 aLinkRange = ScRange( rData.GetCurX(), rData.GetCurY(), rData.GetTabNo() );
3432
3433 rData.GetDocFunc().InsertAreaLink( _rFile, _rFilter, _rOptions, _rSource,
3434 aLinkRange, _nRefreshDelaySeconds, bMove, false );
3435 _rRequest.Done();
3436 }
3437 else
3438 _rRequest.Ignore();
3439 }
3440
3441 namespace {
3442
isDPSourceValid(const ScDPObject & rDPObj)3443 bool isDPSourceValid(const ScDPObject& rDPObj)
3444 {
3445 if (rDPObj.IsImportData())
3446 {
3447 // If the data type is database, check if the database is still valid.
3448 const ScImportSourceDesc* pDesc = rDPObj.GetImportSourceDesc();
3449 if (!pDesc)
3450 return false;
3451
3452 const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
3453 const ScDPDimensionSaveData* pDimData = nullptr;
3454 if (pSaveData)
3455 pDimData = pSaveData->GetExistingDimensionData();
3456
3457 const ScDPCache* pCache = pDesc->CreateCache(pDimData);
3458 if (!pCache)
3459 // cache creation failed, probably due to invalid connection.
3460 return false;
3461 }
3462 return true;
3463 }
3464
RunPivotLayoutDialog(ScModule * pScMod,ScTabViewShell * pTabViewShell,std::unique_ptr<ScDPObject> & pNewDPObject)3465 void RunPivotLayoutDialog(ScModule* pScMod,
3466 ScTabViewShell* pTabViewShell,
3467 std::unique_ptr<ScDPObject>& pNewDPObject)
3468 {
3469 bool bHadNewDPObject = pNewDPObject != nullptr;
3470 pTabViewShell->SetDialogDPObject( std::move(pNewDPObject) );
3471 if ( bHadNewDPObject )
3472 {
3473 // start layout dialog
3474
3475 sal_uInt16 nId = ScPivotLayoutWrapper::GetChildWindowId();
3476 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
3477 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
3478 pScMod->SetRefDialog( nId, pWnd == nullptr );
3479 }
3480 }
3481
SetupRangeForPivotTableDialog(const ScRange & rRange,ScAddress & rDestPos,ScDocument * pDoc,TranslateId & rSrcErrorId,std::unique_ptr<ScDPObject> & pNewDPObject)3482 void SetupRangeForPivotTableDialog(const ScRange& rRange,
3483 ScAddress& rDestPos,
3484 ScDocument* pDoc,
3485 TranslateId& rSrcErrorId,
3486 std::unique_ptr<ScDPObject>& pNewDPObject)
3487 {
3488 ScSheetSourceDesc aShtDesc(pDoc);
3489 aShtDesc.SetSourceRange(rRange);
3490 rSrcErrorId = aShtDesc.CheckSourceRange();
3491 if (!rSrcErrorId)
3492 {
3493 pNewDPObject.reset(new ScDPObject(pDoc));
3494 pNewDPObject->SetSheetDesc( aShtDesc );
3495 }
3496
3497 // output below source data
3498 if ( rRange.aEnd.Row()+2 <= pDoc->MaxRow() - 4 )
3499 rDestPos = ScAddress( rRange.aStart.Col(),
3500 rRange.aEnd.Row()+2,
3501 rRange.aStart.Tab() );
3502 }
3503
ErrorOrRunPivotLayoutDialog(TranslateId pSrcErrorId,const ScAddress & rDestPos,ScModule * pScMod,ScTabViewShell * pTabViewShell,std::unique_ptr<ScDPObject> & pNewDPObject)3504 void ErrorOrRunPivotLayoutDialog(TranslateId pSrcErrorId,
3505 const ScAddress& rDestPos,
3506 ScModule* pScMod,
3507 ScTabViewShell* pTabViewShell,
3508 std::unique_ptr<ScDPObject>& pNewDPObject)
3509 {
3510 if (pSrcErrorId)
3511 {
3512 // Error occurred during data creation. Launch an error and bail out.
3513 std::shared_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
3514 VclMessageType::Info, VclButtonsType::Ok,
3515 ScResId(pSrcErrorId)));
3516 xInfoBox->runAsync(xInfoBox, [] (int) {});
3517 return;
3518 }
3519
3520 if ( pNewDPObject )
3521 pNewDPObject->SetOutRange( ScRange(rDestPos) );
3522
3523 RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject);
3524 }
3525
3526 }
3527
ExecuteDataPilotDialog()3528 void ScCellShell::ExecuteDataPilotDialog()
3529 {
3530 ScModule* pScMod = ScModule::get();
3531 ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
3532 ScViewData& rData = GetViewData();
3533 ScDocument& rDoc = rData.GetDocument();
3534
3535 // ScPivot is no longer used...
3536 ScDPObject* pDPObj = rDoc.GetDPAtCursor(
3537 rData.GetCurX(), rData.GetCurY(),
3538 rData.GetTabNo() );
3539 if ( pDPObj ) // on an existing table?
3540 {
3541 std::unique_ptr<ScDPObject> pNewDPObject;
3542
3543 if (isDPSourceValid(*pDPObj))
3544 pNewDPObject.reset(new ScDPObject(*pDPObj));
3545
3546 RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject);
3547 }
3548 else // create new table
3549 {
3550 // select database range or data
3551 pTabViewShell->GetDBData( true, SC_DB_OLD );
3552 ScMarkData& rMark = GetViewData().GetMarkData();
3553 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
3554 pTabViewShell->MarkDataArea( false );
3555
3556 // output to cursor position for non-sheet data
3557 ScAddress aDestPos( rData.GetCurX(), rData.GetCurY(),
3558 rData.GetTabNo() );
3559
3560 // first select type of source data
3561
3562 bool bEnableExt = ScDPObject::HasRegisteredSources();
3563
3564 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
3565
3566 VclPtr<AbstractScDataPilotSourceTypeDlg> pTypeDlg(
3567 pFact->CreateScDataPilotSourceTypeDlg(
3568 pTabViewShell->GetFrameWeld(), bEnableExt));
3569
3570 // Populate named ranges (if any).
3571 ScRangeName* pRangeName = rDoc.GetRangeName();
3572 if (pRangeName)
3573 {
3574 ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
3575 for (; itr != itrEnd; ++itr)
3576 pTypeDlg->AppendNamedRange(itr->second->GetName());
3577 }
3578
3579 pTypeDlg->StartExecuteAsync([this, pTypeDlg, pTabViewShell,
3580 pScMod, pFact, &rDoc, &rMark, aDestPos](int nResult) mutable {
3581
3582 if (nResult == RET_OK )
3583 {
3584 if ( pTypeDlg->IsExternal() )
3585 {
3586 std::vector<OUString> aSources = ScDPObject::GetRegisteredSources();
3587 VclPtr<AbstractScDataPilotServiceDlg> pServDlg(
3588 pFact->CreateScDataPilotServiceDlg(
3589 pTabViewShell->GetFrameWeld(), aSources));
3590
3591 pServDlg->StartExecuteAsync([pServDlg, pScMod, pTabViewShell,
3592 aDestPos, &rDoc](int nResult2) mutable {
3593 if ( nResult2 == RET_OK )
3594 {
3595 ScDPServiceDesc aServDesc(
3596 pServDlg->GetServiceName(),
3597 pServDlg->GetParSource(),
3598 pServDlg->GetParName(),
3599 pServDlg->GetParUser(),
3600 pServDlg->GetParPass() );
3601 std::unique_ptr<ScDPObject> pNewDPObject(new ScDPObject(&rDoc));
3602 pNewDPObject->SetServiceData( aServDesc );
3603 pNewDPObject->SetOutRange(ScRange(aDestPos));
3604
3605 RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject);
3606 }
3607
3608 pServDlg->disposeOnce();
3609 });
3610 }
3611 else if ( pTypeDlg->IsDatabase() )
3612 {
3613 assert(pFact && "ScAbstractFactory create fail!");
3614 VclPtr<AbstractScDataPilotDatabaseDlg> pDataDlg(
3615 pFact->CreateScDataPilotDatabaseDlg(pTabViewShell->GetFrameWeld()));
3616 assert(pDataDlg && "Dialog create fail!");
3617
3618 pDataDlg->StartExecuteAsync([pDataDlg, pScMod, pTabViewShell,
3619 aDestPos, &rDoc](int nResult2) mutable {
3620 if ( nResult2 == RET_OK )
3621 {
3622 ScImportSourceDesc aImpDesc(&rDoc);
3623 pDataDlg->GetValues( aImpDesc );
3624 std::unique_ptr<ScDPObject> pNewDPObject(new ScDPObject(&rDoc));
3625 pNewDPObject->SetImportDesc( aImpDesc );
3626 pNewDPObject->SetOutRange(ScRange(aDestPos));
3627
3628 RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject);
3629 }
3630
3631 pDataDlg->disposeOnce();
3632 });
3633 }
3634 else
3635 {
3636 TranslateId pSrcErrorId;
3637
3638 if (pTypeDlg->IsNamedRange())
3639 {
3640 std::unique_ptr<ScDPObject> pNewDPObject;
3641 OUString aName = pTypeDlg->GetSelectedNamedRange();
3642 ScSheetSourceDesc aShtDesc(&rDoc);
3643 aShtDesc.SetRangeName(aName);
3644 pSrcErrorId = aShtDesc.CheckSourceRange();
3645 if (!pSrcErrorId)
3646 {
3647 pNewDPObject.reset(new ScDPObject(&rDoc));
3648 pNewDPObject->SetSheetDesc(aShtDesc);
3649 }
3650
3651 ErrorOrRunPivotLayoutDialog(pSrcErrorId, aDestPos, pScMod, pTabViewShell, pNewDPObject);
3652 }
3653 else // selection
3654 {
3655 //! use database ranges (select before type dialog?)
3656 ScRange aRange;
3657 ScMarkType eType = GetViewData().GetSimpleArea(aRange);
3658 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
3659 {
3660 ScDocument* pDoc = &rDoc;
3661
3662 // Shrink the range to the data area.
3663 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
3664 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
3665 if (rDoc.ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
3666 {
3667 aRange.aStart.SetCol(nStartCol);
3668 aRange.aStart.SetRow(nStartRow);
3669 aRange.aEnd.SetCol(nEndCol);
3670 aRange.aEnd.SetRow(nEndRow);
3671 rMark.SetMarkArea(aRange);
3672 pTabViewShell->MarkRange(aRange);
3673 }
3674
3675 if ( rDoc.HasSubTotalCells( aRange ) )
3676 {
3677 // confirm selection if it contains SubTotal cells
3678 std::shared_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
3679 VclMessageType::Question, VclButtonsType::YesNo,
3680 ScResId(STR_DATAPILOT_SUBTOTAL)));
3681 xQueryBox->set_default_response(RET_YES);
3682 xQueryBox->runAsync(xQueryBox, [aRange, pDoc, pTypeDlg, aDestPos,
3683 pScMod, pTabViewShell, pSrcErrorId] (int nResult2) mutable {
3684 if (nResult2 == RET_NO)
3685 return;
3686
3687 std::unique_ptr<ScDPObject> pNewDPObject;
3688 SetupRangeForPivotTableDialog(aRange, aDestPos, pDoc, pSrcErrorId, pNewDPObject);
3689 ErrorOrRunPivotLayoutDialog(pSrcErrorId, aDestPos, pScMod, pTabViewShell, pNewDPObject);
3690 });
3691
3692 pTypeDlg->disposeOnce();
3693 return;
3694 }
3695
3696 std::unique_ptr<ScDPObject> pNewDPObject;
3697 SetupRangeForPivotTableDialog(aRange, aDestPos, pDoc, pSrcErrorId, pNewDPObject);
3698 ErrorOrRunPivotLayoutDialog(pSrcErrorId, aDestPos, pScMod, pTabViewShell, pNewDPObject);
3699 }
3700 }
3701 }
3702 }
3703
3704 pTypeDlg->disposeOnce();
3705 });
3706 }
3707 }
3708
ExecuteXMLSourceDialog()3709 void ScCellShell::ExecuteXMLSourceDialog()
3710 {
3711 ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
3712 if (!pTabViewShell)
3713 return;
3714
3715 sal_uInt16 nId = ScXMLSourceDlgWrapper::GetChildWindowId();
3716 SfxViewFrame& rViewFrame = pTabViewShell->GetViewFrame();
3717 SfxChildWindow* pWnd = rViewFrame.GetChildWindow(nId);
3718 ScModule::get()->SetRefDialog(nId, pWnd == nullptr);
3719 }
3720
ExecuteSubtotals(SfxRequest & rReq)3721 void ScCellShell::ExecuteSubtotals(SfxRequest& rReq)
3722 {
3723 ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
3724 const SfxItemSet* pArgs = rReq.GetArgs();
3725 if ( pArgs )
3726 {
3727 pTabViewShell->DoSubTotals( pArgs->Get( SCITEM_SUBTDATA ).
3728 GetSubTotalData() );
3729 rReq.Done();
3730 return;
3731 }
3732
3733 ScopedVclPtr<SfxAbstractTabDialog> pDlg;
3734 ScSubTotalParam aSubTotalParam;
3735 SfxItemSet aArgSet(SfxItemSet::makeFixedSfxItemSet<SCITEM_SUBTDATA, SCITEM_SUBTDATA>(GetPool()));
3736
3737 bool bAnonymous;
3738
3739 // Only get existing named database range.
3740 ScDBData* pDBData = pTabViewShell->GetDBData(true, SC_DB_OLD);
3741 if (pDBData)
3742 bAnonymous = false;
3743 else
3744 {
3745 // No existing DB data at this position. Create an
3746 // anonymous DB.
3747 bAnonymous = true;
3748 pDBData = pTabViewShell->GetAnonymousDBData();
3749 ScRange aDataRange;
3750 pDBData->GetArea(aDataRange);
3751 pTabViewShell->MarkRange(aDataRange, false);
3752 }
3753
3754 pDBData->GetSubTotalParam( aSubTotalParam );
3755
3756 ScDocument& rDoc = GetViewData().GetDocument();
3757 SCTAB nTab = GetViewData().GetTabNo();
3758 if (!rDoc.GetTotalsRowBelow(nTab))
3759 aSubTotalParam.bSummaryBelow = false;
3760
3761 aSubTotalParam.bRemoveOnly = false;
3762 if (bAnonymous)
3763 {
3764 // Preset sort formatting along with values and also create formula
3765 // cells with "needs formatting". Subtotals on data of different types
3766 // doesn't make much sense anyway.
3767 aSubTotalParam.bIncludePattern = true;
3768 }
3769
3770 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, &GetViewData(), &aSubTotalParam ) );
3771 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
3772 pDlg.disposeAndReset(pFact->CreateScSubTotalDlg(pTabViewShell->GetFrameWeld(), aArgSet));
3773 pDlg->SetCurPageId(u"1stgroup"_ustr);
3774
3775 short bResult = pDlg->Execute();
3776
3777 if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
3778 {
3779 const SfxItemSet* pOutSet = nullptr;
3780
3781 if ( bResult == RET_OK )
3782 {
3783 pOutSet = pDlg->GetOutputItemSet();
3784 aSubTotalParam =
3785 pOutSet->Get( SCITEM_SUBTDATA ).GetSubTotalData();
3786 }
3787 else // if (bResult == SCRET_REMOVE)
3788 {
3789 pOutSet = &aArgSet;
3790 aSubTotalParam.bRemoveOnly = true;
3791 aSubTotalParam.bReplace = true;
3792 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
3793 &GetViewData(),
3794 &aSubTotalParam ) );
3795 }
3796
3797 pTabViewShell->DoSubTotals( aSubTotalParam );
3798 rReq.Done( *pOutSet );
3799 }
3800 else
3801 GetViewData().GetDocShell().CancelAutoDBRange();
3802 }
3803
ExecuteFillSingleEdit()3804 void ScCellShell::ExecuteFillSingleEdit()
3805 {
3806 ScAddress aCurPos = GetViewData().GetCurPos();
3807
3808 OUString aInit;
3809
3810 if (aCurPos.Row() > 0)
3811 {
3812 // Get the initial text value from the above cell.
3813
3814 ScDocument& rDoc = GetViewData().GetDocument();
3815 ScAddress aPrevPos = aCurPos;
3816 aPrevPos.IncRow(-1);
3817 ScRefCellValue aCell(rDoc, aPrevPos);
3818
3819 if (aCell.getType() == CELLTYPE_FORMULA)
3820 {
3821 aInit = "=";
3822 const ScTokenArray* pCode = aCell.getFormula()->GetCode();
3823 sc::TokenStringContext aCxt(rDoc, rDoc.GetGrammar());
3824 aInit += pCode->CreateString(aCxt, aCurPos);
3825 }
3826 else
3827 aInit = aCell.getString(rDoc);
3828 }
3829
3830 ScModule::get()->SetInputMode(SC_INPUT_TABLE, &aInit);
3831 }
3832
CellShell_Impl()3833 CellShell_Impl::CellShell_Impl() :
3834 m_pRequest( nullptr ) {}
3835
~CellShell_Impl()3836 CellShell_Impl::~CellShell_Impl()
3837 {
3838 }
3839 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
3840