Coverage Report

Created: 2026-02-14 09:37

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