Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/docshell/docsh4.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/frame/Desktop.hpp>
23
24
#include <scitems.hxx>
25
#include <editeng/flstitem.hxx>
26
#include <sfx2/fcontnr.hxx>
27
#include <sfx2/linkmgr.hxx>
28
#include <sfx2/objface.hxx>
29
#include <sfx2/docfile.hxx>
30
#include <sfx2/docfilt.hxx>
31
#include <svtools/ehdl.hxx>
32
#include <svtools/langtab.hxx>
33
#include <basic/sbxcore.hxx>
34
#include <basic/sberrors.hxx>
35
#include <svtools/sfxecode.hxx>
36
#include <svx/ofaitem.hxx>
37
#include <svx/svdograf.hxx>
38
#include <svl/stritem.hxx>
39
#include <svl/whiter.hxx>
40
#include <vcl/svapp.hxx>
41
#include <vcl/weld/MessageDialog.hxx>
42
#include <vcl/weld/WaitObject.hxx>
43
#include <svx/dataaccessdescriptor.hxx>
44
#include <svx/drawitem.hxx>
45
#include <svx/fmshell.hxx>
46
#include <svx/pageitem.hxx>
47
#include <editeng/sizeitem.hxx>
48
#include <editeng/paperinf.hxx>
49
#include <sfx2/passwd.hxx>
50
#include <sfx2/filedlghelper.hxx>
51
#include <sfx2/dispatch.hxx>
52
#include <sfx2/sfxdlg.hxx>
53
#include <svl/PasswordHelper.hxx>
54
#include <svl/documentlockfile.hxx>
55
#include <svl/sharecontrolfile.hxx>
56
#include <tools/json_writer.hxx>
57
#include <unotools/securityoptions.hxx>
58
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
59
#include <sal/log.hxx>
60
#include <unotools/charclass.hxx>
61
#include <comphelper/diagnose_ex.hxx>
62
#include <o3tl/string_view.hxx>
63
64
#include <comphelper/lok.hxx>
65
#include <comphelper/processfactory.hxx>
66
#include <comphelper/propertyvalue.hxx>
67
#include <docuno.hxx>
68
69
#include <docsh.hxx>
70
#include "docshimp.hxx"
71
#include <docfunc.hxx>
72
#include <scres.hrc>
73
#include <strings.hrc>
74
#include <stlsheet.hxx>
75
#include <stlpool.hxx>
76
#include <appoptio.hxx>
77
#include <globstr.hrc>
78
#include <global.hxx>
79
#include <dbdocfun.hxx>
80
#include <printfun.hxx>
81
#include <viewdata.hxx>
82
#include <tabvwsh.hxx>
83
#include <impex.hxx>
84
#include <undodat.hxx>
85
#include <undocell.hxx>
86
#include <inputhdl.hxx>
87
#include <dbdata.hxx>
88
#include <servobj.hxx>
89
#include <rangenam.hxx>
90
#include <scmod.hxx>
91
#include <chgviset.hxx>
92
#include <reffact.hxx>
93
#include <chartlis.hxx>
94
#include <chartpos.hxx>
95
#include <tablink.hxx>
96
#include <drwlayer.hxx>
97
#include <svx/fillbitmaplink.hxx>
98
#include <svx/svdpage.hxx>
99
#include <docoptio.hxx>
100
#include <undostyl.hxx>
101
#include <rangeseq.hxx>
102
#include <chgtrack.hxx>
103
#include <com/sun/star/document/UpdateDocMode.hpp>
104
#include <scresid.hxx>
105
#include <scabstdlg.hxx>
106
#include <sharedocdlg.hxx>
107
#include <conditio.hxx>
108
#include <sheetevents.hxx>
109
#include <formulacell.hxx>
110
#include <documentlinkmgr.hxx>
111
#include <tablestyle.hxx>
112
#include <memory>
113
#include <sfx2/notebookbar/SfxNotebookBar.hxx>
114
#include <helpids.h>
115
#include <editeng/eeitem.hxx>
116
#include <editeng/langitem.hxx>
117
#include <editeng/urlfieldhelper.hxx>
118
#include <officecfg/Office/Common.hxx>
119
120
#include <svx/xdef.hxx>
121
#include <editeng/lrspitem.hxx> // Defines SvxLRSpaceItem
122
#include <editeng/ulspitem.hxx> // Defines SvxULSpaceItem
123
#include <sfx2/lokhelper.hxx>
124
125
using namespace ::com::sun::star;
126
127
void ScDocShell::SetInitialLinkUpdate( const SfxMedium* pMed )
128
25.9k
{
129
25.9k
    if (pMed)
130
25.9k
    {
131
25.9k
        const SfxUInt16Item* pUpdateDocItem = pMed->GetItemSet().GetItem(SID_UPDATEDOCMODE, false);
132
25.9k
        m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
133
25.9k
    }
134
135
    // GetLinkUpdateModeState() evaluates m_nCanUpdate so that must have
136
    // been set first. Do not override an already forbidden LinkUpdate (the
137
    // default is allow).
138
25.9k
    comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
139
25.9k
    if (rEmbeddedObjectContainer.getUserAllowsLinkUpdate())
140
25.9k
    {
141
        // For anything else than LM_ALWAYS we need user confirmation.
142
25.9k
        rEmbeddedObjectContainer.setUserAllowsLinkUpdate( GetLinkUpdateModeState() == LM_ALWAYS);
143
25.9k
    }
144
25.9k
}
145
146
ScLkUpdMode ScDocShell::GetLinkUpdateModeState() const
147
25.9k
{
148
25.9k
    ScLkUpdMode nSet;
149
25.9k
    if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
150
25.9k
        nSet = LM_NEVER;
151
0
    else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
152
0
        nSet = LM_ALWAYS;
153
0
    else
154
0
    {
155
0
        nSet = GetDocument().GetLinkMode();
156
0
        if (nSet == LM_UNKNOWN)
157
0
        {
158
0
            ScAppOptions aAppOptions = ScModule::get()->GetAppOptions();
159
0
            nSet = aAppOptions.GetLinkMode();
160
0
        }
161
0
    }
162
163
25.9k
    if (nSet != LM_NEVER
164
0
        && (SvtSecurityOptions::isUntrustedReferer(
165
0
                GetMedium() == nullptr ? OUString() : GetMedium()->GetName())
166
0
            || (IsDocShared() && SvtSecurityOptions::isUntrustedReferer(GetSharedFileURL()))))
167
0
    {
168
0
        nSet = LM_NEVER;
169
0
    }
170
25.9k
    else if (nSet == LM_ALWAYS
171
0
            && !(SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks(
172
0
                    GetMedium() == nullptr ? OUString() : GetMedium()->GetName())
173
0
                || (IsDocShared()
174
0
                    && SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks(
175
0
                        GetSharedFileURL()))))
176
0
    {
177
0
        nSet = LM_ON_DEMAND;
178
0
    }
179
25.9k
    if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
180
0
            && nSet == LM_ON_DEMAND)
181
0
    {
182
0
        nSet = LM_NEVER;
183
0
    }
184
185
25.9k
    return nSet;
186
25.9k
}
187
188
void ScDocShell::AllowLinkUpdate()
189
0
{
190
0
    m_pDocument->SetLinkFormulaNeedingCheck(false);
191
0
    getEmbeddedObjectContainer().setUserAllowsLinkUpdate(true);
192
0
}
193
194
void ScDocShell::ReloadAllLinks()
195
0
{
196
0
    AllowLinkUpdate();
197
198
0
    ReloadTabLinks();
199
0
    weld::Window *pDialogParent = GetActiveDialogParent();
200
0
    m_pDocument->UpdateExternalRefLinks(pDialogParent);
201
202
0
    bool bAnyDde = m_pDocument->GetDocLinkManager().updateDdeOrOleOrWebServiceLinks(pDialogParent);
203
204
0
    if (bAnyDde)
205
0
    {
206
        //  calculate formulas and paint like in the TrackTimeHdl
207
0
        m_pDocument->TrackFormulas();
208
0
        Broadcast(SfxHint(SfxHintId::ScDataChanged));
209
210
        //  Should FID_DATACHANGED become asynchronous some time
211
        //  (e.g., with Invalidate at Window), an update needs to be forced here.
212
0
    }
213
214
0
    m_pDocument->UpdateAreaLinks();
215
216
    // Draw-layer fill bitmap host links are registered when SID_UPDATETABLINKS
217
    // runs at load, so they are not re-scanned here, only updated.
218
0
    if (sfx2::LinkManager* pLinkMgr = m_pDocument->GetDocLinkManager().getLinkManager(false))
219
0
    {
220
0
        registerDeferredFormImageLinks(GetDeferredFormControlImages(), *pLinkMgr);
221
0
        ClearDeferredFormControlImages();
222
0
        pLinkMgr->UpdateAllLinks(false, nullptr, u""_ustr);
223
0
    }
224
0
}
225
226
void ScDocShell::PerformLinkUpdate()
227
0
{
228
0
    ScDocument& rDoc = GetDocument();
229
0
    if (rDoc.HasLinkFormulaNeedingCheck() && rDoc.GetDocLinkManager().hasExternalRefLinks())
230
0
    {
231
        // If we have WEBSERVICE/Dde link and other external links in the document, it might indicate some
232
        // exfiltration attempt, add *another* warning about this on top of the "Security Warning"
233
        // shown in the infobar before they got here.
234
0
        std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetActiveDialogParent(),
235
0
                                                       VclMessageType::Warning, VclButtonsType::YesNo,
236
0
                                                       ScResId(STR_TRUST_DOCUMENT_WARNING)));
237
0
        xQueryBox->set_secondary_text(ScResId(STR_WEBSERVICE_WITH_LINKS_WARNING));
238
0
        xQueryBox->set_default_response(RET_NO);
239
0
        if (xQueryBox->run() != RET_YES)
240
0
            return;
241
0
    }
242
243
0
    ReloadAllLinks();
244
0
}
245
246
bool ScDocShell::HasExternalLinks() const
247
0
{
248
0
    return GetDocument().HasExternalLinks() || !GetDeferredFormControlImages().empty();
249
0
}
250
251
namespace
252
{
253
254
void lcl_setLOKLocale(const ScTabViewShell& rViewShell, const LanguageType eLang)
255
0
{
256
0
    OUString aLang = LanguageTag(eLang).getBcp47();
257
    /// This is only used for building the lok calendar as of date.
258
    /// Don't change the view language as it affects the js-dialog language as well.
259
0
    SfxLokHelper::setViewLocale(SfxLokHelper::getView(rViewShell), aLang);
260
0
}
261
262
} // end anonymous namespace
263
264
void ScDocShell::SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl)
265
0
{
266
0
    if (comphelper::LibreOfficeKit::isActive())
267
0
    {
268
0
        if (ScTabViewShell* pViewShell = GetBestViewShell())
269
0
        {
270
0
            lcl_setLOKLocale(*pViewShell, eLatin);
271
0
        }
272
0
    }
273
274
    // Update the document language even in lok mode as
275
    // the spell-check is still based on document language.
276
0
    GetDocument().SetLanguage(eLatin, eCjk, eCtl);
277
0
}
278
279
void ScDocShell::Execute( SfxRequest& rReq )
280
0
{
281
0
    const SfxItemSet* pReqArgs = rReq.GetArgs();
282
0
    SfxBindings* pBindings = GetViewBindings();
283
0
    bool bUndo (m_pDocument->IsUndoEnabled());
284
285
0
    sal_uInt16 nSlot = rReq.GetSlot();
286
0
    switch ( nSlot )
287
0
    {
288
0
        case SID_SC_SETTEXT:
289
0
        {
290
0
            const SfxPoolItem* pColItem;
291
0
            const SfxPoolItem* pRowItem;
292
0
            const SfxPoolItem* pTabItem;
293
0
            const SfxPoolItem* pTextItem;
294
0
            if( pReqArgs && pReqArgs->HasItem( FN_PARAM_1, &pColItem ) &&
295
0
                            pReqArgs->HasItem( FN_PARAM_2, &pRowItem ) &&
296
0
                            pReqArgs->HasItem( FN_PARAM_3, &pTabItem ) &&
297
0
                            pReqArgs->HasItem( SID_SC_SETTEXT, &pTextItem ) )
298
0
            {
299
                //  parameters are  1-based !!!
300
0
                SCCOL nCol = static_cast<const SfxInt16Item*>(pColItem)->GetValue() - 1;
301
0
                SCROW nRow = static_cast<const SfxInt32Item*>(pRowItem)->GetValue() - 1;
302
0
                SCTAB nTab = static_cast<const SfxInt16Item*>(pTabItem)->GetValue() - 1;
303
304
0
                SCTAB nTabCount = m_pDocument->GetTableCount();
305
0
                if ( m_pDocument->ValidCol(nCol) && m_pDocument->ValidRow(nRow) && ValidTab(nTab,nTabCount) )
306
0
                {
307
0
                    if ( m_pDocument->IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) )
308
0
                    {
309
0
                        OUString aVal = static_cast<const SfxStringItem*>(pTextItem)->GetValue();
310
0
                        m_pDocument->SetString( nCol, nRow, nTab, aVal );
311
312
0
                        PostPaintCell( nCol, nRow, nTab );
313
0
                        SetDocumentModified();
314
315
0
                        rReq.Done();
316
0
                        break;
317
0
                    }
318
0
                    else                // protected cell
319
0
                    {
320
#if HAVE_FEATURE_SCRIPTING
321
                        SbxBase::SetError( ERRCODE_BASIC_BAD_PARAMETER );      //! which error ?
322
#endif
323
0
                        break;
324
0
                    }
325
0
                }
326
0
            }
327
#if HAVE_FEATURE_SCRIPTING
328
            SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
329
#endif
330
0
        }
331
0
        break;
332
333
0
        case SID_SBA_IMPORT:
334
0
        {
335
0
            if (pReqArgs)
336
0
            {
337
0
                const SfxPoolItem* pItem;
338
0
                svx::ODataAccessDescriptor aDesc;
339
0
                if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
340
0
                {
341
0
                    uno::Any aAny = static_cast<const SfxUnoAnyItem*>(pItem)->GetValue();
342
0
                    uno::Sequence<beans::PropertyValue> aProperties;
343
0
                    if ( aAny >>= aProperties )
344
0
                        aDesc.initializeFrom( aProperties );
345
0
                }
346
347
0
                OUString sTarget;
348
0
                if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET )
349
0
                    sTarget = static_cast<const SfxStringItem*>(pItem)->GetValue();
350
351
0
                bool bIsNewArea = true;         // Default sal_True (no inquiry)
352
0
                if ( pReqArgs->GetItemState( FN_PARAM_2, true, &pItem ) == SfxItemState::SET )
353
0
                    bIsNewArea = static_cast<const SfxBoolItem*>(pItem)->GetValue();
354
355
                // if necessary, create new database area
356
0
                bool bMakeArea = false;
357
0
                if (bIsNewArea)
358
0
                {
359
0
                    ScDBCollection* pDBColl = m_pDocument->GetDBCollection();
360
0
                    if ( !pDBColl || !pDBColl->getNamedDBs().findByUpperName(ScGlobal::getCharClass().uppercase(sTarget)) )
361
0
                    {
362
0
                        ScAddress aPos;
363
0
                        if ( aPos.Parse( sTarget, *m_pDocument, m_pDocument->GetAddressConvention() ) & ScRefFlags::VALID )
364
0
                        {
365
0
                            bMakeArea = true;
366
0
                            if (bUndo)
367
0
                            {
368
0
                                OUString aStrImport = ScResId( STR_UNDO_IMPORTDATA );
369
0
                                ViewShellId nViewShellId(-1);
370
0
                                if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell())
371
0
                                    nViewShellId = pViewSh->GetViewShellId();
372
0
                                GetUndoManager()->EnterListAction( aStrImport, aStrImport, 0, nViewShellId );
373
0
                            }
374
375
0
                            ScDBData* pDBData = GetDBData( ScRange(aPos), SC_DB_IMPORT, ScGetDBSelection::Keep );
376
0
                            assert(pDBData && "Cannot create DB data");
377
0
                            sTarget = pDBData->GetName();
378
0
                        }
379
0
                    }
380
0
                }
381
382
                // inquire, before old DB range gets overwritten
383
0
                bool bDo = true;
384
0
                if (!bIsNewArea)
385
0
                {
386
0
                    OUString aTemplate = ScResId( STR_IMPORT_REPLACE );
387
0
                    OUString aMessage = o3tl::getToken(aTemplate, 0, '#' )
388
0
                        + sTarget
389
0
                        + o3tl::getToken(aTemplate, 1, '#' );
390
391
0
                    std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(nullptr,
392
0
                                                                   VclMessageType::Question, VclButtonsType::YesNo,
393
0
                                                                   aMessage));
394
0
                    xQueryBox->set_default_response(RET_YES);
395
0
                    bDo = xQueryBox->run() == RET_YES;
396
0
                }
397
398
0
                if (bDo)
399
0
                {
400
0
                    ScDBDocFunc(*this).UpdateImport( sTarget, aDesc );
401
0
                    rReq.Done();
402
403
                    //  UpdateImport also updates the internal operations
404
0
                }
405
0
                else
406
0
                    rReq.Ignore();
407
408
0
                if ( bMakeArea && bUndo)
409
0
                    GetUndoManager()->LeaveListAction();
410
0
            }
411
0
            else
412
0
            {
413
0
                OSL_FAIL( "arguments expected" );
414
0
            }
415
0
        }
416
0
        break;
417
418
0
        case SID_CHART_SOURCE:
419
0
        case SID_CHART_ADDSOURCE:
420
0
            ExecuteChartSource(rReq);
421
0
            break;
422
423
0
        case FID_AUTO_CALC:
424
0
            {
425
0
                bool bNewVal;
426
0
                const SfxPoolItem* pItem;
427
0
                if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) )
428
0
                    bNewVal = static_cast<const SfxBoolItem*>(pItem)->GetValue();
429
0
                else
430
0
                    bNewVal = !m_pDocument->GetAutoCalc();     // Toggle for menu
431
0
                m_pDocument->SetAutoCalc( bNewVal );
432
0
                SetDocumentModified();
433
0
                if (pBindings)
434
0
                {
435
0
                    pBindings->Invalidate( FID_AUTO_CALC );
436
0
                }
437
0
                rReq.AppendItem( SfxBoolItem( FID_AUTO_CALC, bNewVal ) );
438
0
                rReq.Done();
439
0
            }
440
0
            break;
441
0
        case SID_OPEN_HYPERLINK:
442
0
            {
443
0
                ScViewData* pViewData = GetViewData();
444
0
                if ( !pViewData )
445
0
                {
446
0
                    rReq.Ignore();
447
0
                    break;
448
0
                }
449
450
0
                if (ScModule::get()->IsEditMode())
451
0
                {
452
0
                    if (EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart()))
453
0
                    {
454
0
                        const SvxFieldItem* pFieldItem = pEditView->GetFieldAtSelection(/*bAlsoCheckBeforeCursor=*/true);
455
0
                        const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr;
456
0
                        if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
457
0
                        {
458
0
                            ScGlobal::OpenURL(pURLField->GetURL(), pURLField->GetTargetFrame(), true);
459
0
                            rReq.Done();
460
0
                            break;
461
0
                        }
462
0
                    }
463
0
                }
464
0
                else
465
0
                {
466
0
                    if (ScGridWindow* pWin = pViewData->GetActiveWin())
467
0
                    {
468
0
                        std::vector<UrlData> vUrls = pWin->GetEditUrls(pViewData->GetCurPos());
469
0
                        if (!vUrls.empty())
470
0
                        {
471
0
                            for (UrlData& data : vUrls)
472
0
                            {
473
0
                                ScGlobal::OpenURL(data.aUrl, data.aTarget, true);
474
0
                            }
475
0
                            rReq.Done();
476
0
                            break;
477
0
                        }
478
0
                    }
479
0
                }
480
0
                rReq.Ignore();
481
0
            }
482
0
            break;
483
0
        case FID_RECALC:
484
0
            DoRecalc( rReq.IsAPI() );
485
0
            rReq.Done();
486
0
            break;
487
0
        case FID_HARD_RECALC:
488
0
            DoHardRecalc();
489
0
            rReq.Done();
490
0
            break;
491
0
        case SID_UPDATETABLINKS:
492
0
            {
493
                // Draw-layer fill bitmap links are registered as the shapes are
494
                // imported, via the draw model's link tracker. Form control
495
                // images are collected during import and registered here.
496
0
                if (sfx2::LinkManager* pLinkMgr = m_pDocument->GetDocLinkManager().getLinkManager(false))
497
0
                {
498
0
                    registerDeferredFormImageLinks(GetDeferredFormControlImages(), *pLinkMgr);
499
0
                    ClearDeferredFormControlImages();
500
0
                }
501
502
0
                ScLkUpdMode nSet = GetLinkUpdateModeState();
503
504
0
                if (nSet == LM_ALWAYS)
505
0
                {
506
0
                    ReloadAllLinks();
507
0
                    rReq.Done();
508
0
                }
509
0
                else if (nSet == LM_NEVER)
510
0
                {
511
0
                    getEmbeddedObjectContainer().setUserAllowsLinkUpdate(false);
512
0
                    CheckPendingLinkUpdateInfobar();
513
0
                    rReq.Ignore();
514
0
                }
515
0
                else if (nSet == LM_ON_DEMAND)
516
0
                {
517
0
                    ShowLinkUpdateInfobar();
518
0
                    rReq.Done();
519
0
                }
520
0
            }
521
0
            break;
522
523
0
        case SID_REIMPORT_AFTER_LOAD:
524
0
            {
525
                //  Is called after loading if there are DB areas with omitted data
526
527
0
                bool bDone = false;
528
0
                ScDBCollection* pDBColl = m_pDocument->GetDBCollection();
529
530
0
                if ((m_nCanUpdate != css::document::UpdateDocMode::NO_UPDATE) &&
531
0
                   (m_nCanUpdate != css::document::UpdateDocMode::QUIET_UPDATE))
532
0
                {
533
0
                    ScRange aRange;
534
0
                    ScTabViewShell* pViewSh = GetBestViewShell();
535
0
                    OSL_ENSURE(pViewSh,"SID_REIMPORT_AFTER_LOAD: no View");
536
0
                    if (pViewSh && pDBColl)
537
0
                    {
538
0
                        std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetActiveDialogParent(),
539
0
                                                                       VclMessageType::Question, VclButtonsType::YesNo,
540
0
                                                                       ScResId(STR_REIMPORT_AFTER_LOAD)));
541
0
                        xQueryBox->set_default_response(RET_YES);
542
0
                        if (xQueryBox->run() == RET_YES)
543
0
                        {
544
0
                            ScDBCollection::NamedDBs& rDBs = pDBColl->getNamedDBs();
545
0
                            for (const auto& rxDB : rDBs)
546
0
                            {
547
0
                                ScDBData& rDBData = *rxDB;
548
0
                                if ( rDBData.IsStripData() &&
549
0
                                     rDBData.HasImportParam() && !rDBData.HasImportSelection() )
550
0
                                {
551
0
                                    rDBData.GetArea(aRange);
552
0
                                    pViewSh->MarkRange(aRange);
553
554
                                    //  Import and internal operations like SID_REFRESH_DBAREA
555
                                    //  (inquiry for import not needed here)
556
557
0
                                    ScImportParam aImportParam;
558
0
                                    rDBData.GetImportParam( aImportParam );
559
0
                                    bool bContinue = pViewSh->ImportData( aImportParam );
560
0
                                    rDBData.SetImportParam( aImportParam );
561
562
                                    //  mark (size may have changed)
563
0
                                    rDBData.GetArea(aRange);
564
0
                                    pViewSh->MarkRange(aRange);
565
566
0
                                    if ( bContinue )    // error at import -> abort
567
0
                                    {
568
                                        //  internal operations, if some where saved
569
570
0
                                        if ( rDBData.HasQueryParam() || rDBData.HasSortParam() ||
571
0
                                             rDBData.HasSubTotalParam() )
572
0
                                            pViewSh->RepeatDB();
573
574
                                        //  pivot tables, which have the range as source data
575
576
0
                                        RefreshPivotTables(aRange);
577
0
                                    }
578
0
                                }
579
0
                            }
580
0
                            bDone = true;
581
0
                        }
582
0
                    }
583
0
                }
584
585
0
                if ( !bDone && pDBColl )
586
0
                {
587
                    //  if not, but then update the dependent formulas
588
                    //! also for individual ranges, which cannot be updated
589
590
0
                    m_pDocument->CalcAll();        //! only for the dependent
591
0
                    PostDataChanged();
592
0
                }
593
594
0
                if (bDone)
595
0
                    rReq.Done();
596
0
                else
597
0
                    rReq.Ignore();
598
0
            }
599
0
            break;
600
601
0
            case SID_ATTR_PAGE_ORIENTATION: // .uno:Orientation
602
0
            {
603
0
                const SfxBoolItem* pBool = rReq.GetArg<SfxBoolItem>(SID_ATTR_PAGE_ORIENTATION);
604
605
0
                if (!pBool) // nothing supplied  -> do nothing
606
0
                {
607
0
                    rReq.Done();
608
0
                    break;
609
0
                }
610
0
                ScViewData* pViewData = GetViewData();
611
0
                if (!pViewData)
612
0
                    break;
613
614
0
                ScDocument& rDoc = GetDocument();
615
0
                const SCTAB nTab = pViewData->CurrentTabForData();
616
617
                // obtain the page-style’s ItemSet
618
0
                OUString aStyleName = rDoc.GetPageStyle(nTab);
619
0
                ScStyleSheetPool* pPagePool = rDoc.GetStyleSheetPool();
620
0
                if (!pPagePool)
621
0
                    break;
622
0
                SfxStyleSheetBase* pStyle = pPagePool->Find(aStyleName, SfxStyleFamily::Page);
623
0
                if (!pStyle)
624
0
                    break;
625
626
0
                SfxItemSet& rSet = pStyle->GetItemSet();
627
628
0
                const SvxPageItem& rOldPageItem = rSet.Get(ATTR_PAGE);
629
0
                const SvxSizeItem& rOldSizeItem = rSet.Get(ATTR_PAGE_SIZE);
630
631
0
                bool bDesiredLandscape = pBool->GetValue();
632
0
                bool bCurrentLandscape = rOldPageItem.IsLandscape();
633
634
0
                if (bDesiredLandscape == bCurrentLandscape) // already correct
635
0
                {
636
0
                    rReq.Done();
637
0
                    break;
638
0
                }
639
                //  apply the change: flip orientation and swap paper size
640
0
                SvxPageItem aNewPageItem(ATTR_PAGE);
641
0
                aNewPageItem.SetLandscape(bDesiredLandscape);
642
643
0
                Size aOld = rOldSizeItem.GetSize();
644
                // coverity[swapped_arguments : FALSE] - this is in the correct order
645
0
                Size aNew(aOld.Height(), aOld.Width()); // swap W/H
646
0
                SvxSizeItem aNewSizeItem(ATTR_PAGE_SIZE, aNew);
647
648
0
                rSet.Put(aNewPageItem);
649
0
                rSet.Put(aNewSizeItem);
650
651
0
                SetDocumentModified();
652
0
                PostPaintGridAll(); // repaint sheet
653
654
0
                if (pBindings) {
655
656
0
                    pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION);
657
0
                    pBindings->Invalidate(SID_ATTR_PAGE_SIZE);
658
0
                }
659
660
0
                rReq.Done();
661
0
            }
662
0
            break;
663
0
            case SID_SC_ATTR_PAGE_SIZE:
664
0
            {
665
0
                const SfxUInt16Item* pPaperFormatInt
666
0
                    = rReq.GetArg<SfxUInt16Item>(SID_SC_ATTR_PAGE_SIZE);
667
0
                if (!pPaperFormatInt)
668
0
                    break;
669
670
0
                Paper ePaper = static_cast<Paper>(pPaperFormatInt->GetValue());
671
0
                if (ePaper >= NUM_PAPER_ENTRIES
672
0
                    && ePaper != PAPER_USER) // PAPER_USER is a valid special case
673
0
                {
674
0
                    break;
675
0
                }
676
677
0
                Size aNewSize = SvxPaperInfo::GetPaperSize(ePaper);
678
679
0
                ScViewData* pViewData = GetViewData();
680
0
                if (!pViewData)
681
0
                    break;
682
0
                ScDocument& rDoc = GetDocument();
683
0
                const SCTAB nTab = pViewData->CurrentTabForData();
684
0
                OUString aStyleName = rDoc.GetPageStyle(nTab);
685
0
                ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
686
0
                SfxStyleSheetBase* pStyleSheet = pStylePool->Find(aStyleName, SfxStyleFamily::Page);
687
0
                if (!pStyleSheet)
688
0
                    break;
689
690
0
                SfxItemSet& rSet = pStyleSheet->GetItemSet();
691
0
                const SvxSizeItem& rOldSizeItem = rSet.Get(ATTR_PAGE_SIZE);
692
693
                // Only apply if the size is actually different
694
0
                if (aNewSize == rOldSizeItem.GetSize())
695
0
                {
696
0
                    rReq.Done();
697
0
                    break;
698
0
                }
699
700
0
                SvxSizeItem aNewSizeItem(ATTR_PAGE_SIZE, aNewSize);
701
0
                rSet.Put(aNewSizeItem);
702
703
                // Also update the orientation flag to be consistent with the new dimensions
704
0
                const SvxPageItem& rOldPageItem = rSet.Get(ATTR_PAGE);
705
0
                bool bNewIsLandscape = aNewSize.Width() > aNewSize.Height();
706
0
                if (bNewIsLandscape != rOldPageItem.IsLandscape())
707
0
                {
708
0
                    SvxPageItem aNewPageItem(ATTR_PAGE);
709
0
                    aNewPageItem.SetLandscape(bNewIsLandscape);
710
0
                    rSet.Put(aNewPageItem);
711
0
                }
712
713
0
                SetDocumentModified();
714
0
                PostPaintGridAll();
715
716
0
                if (pBindings)
717
0
                {
718
0
                    pBindings->Invalidate(SID_ATTR_PAGE_SIZE);
719
0
                    pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION);
720
0
                }
721
722
0
                rReq.Done();
723
0
            }
724
0
            break;
725
0
        case SID_SC_ATTR_PAGE_MARGIN:
726
0
        {
727
0
            const SvxLRSpaceItem* pLR = rReq.GetArg(SID_ATTR_LRSPACE);
728
0
            if (!pLR) {
729
0
                SAL_WARN( "sc", " Left & Right margins are missing");
730
0
                break;
731
0
            }
732
733
0
            SvxIndentValue nLeft = pLR->GetLeft();
734
0
            SvxIndentValue nRight = pLR->GetRight();
735
736
0
            const SvxULSpaceItem* pUL = rReq.GetArg(SID_ATTR_ULSPACE);
737
0
            if (!pUL) {
738
0
                SAL_WARN( "sc", " Top & Bottom margins are missing");
739
0
                break;
740
0
            }
741
0
            long nTop = pUL->GetUpper();
742
0
            long nBottom = pUL->GetLower();
743
744
0
            ScViewData* pViewData = GetViewData();
745
0
            if (!pViewData)
746
0
            {
747
0
                break;
748
0
            }
749
750
0
            ScDocument& rDoc = GetDocument();
751
0
            const SCTAB nTab = pViewData->CurrentTabForData();
752
0
            OUString aStyleName = rDoc.GetPageStyle(nTab);
753
0
            ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
754
0
            SfxStyleSheetBase* pStyleSheet = pStylePool->Find(aStyleName, SfxStyleFamily::Page);
755
0
            assert(pStyleSheet);
756
0
            SfxItemSet& rSet = pStyleSheet->GetItemSet();
757
758
0
            SvxLRSpaceItem aLRItem(ATTR_LRSPACE);
759
0
            aLRItem.SetLeft(nLeft);
760
0
            aLRItem.SetRight(nRight);
761
0
            rSet.Put(aLRItem);
762
763
0
            SvxULSpaceItem aULItem(ATTR_ULSPACE);
764
0
            aULItem.SetUpper(nTop);
765
0
            aULItem.SetLower(nBottom);
766
0
            rSet.Put(aULItem);
767
768
0
            SetDocumentModified();
769
770
0
            PostPaintGridAll();
771
772
0
            if (pBindings)
773
0
            {
774
0
                pBindings->Invalidate(SID_SC_ATTR_PAGE_MARGIN);
775
0
                pBindings->Invalidate(SID_ATTR_LRSPACE);
776
0
                pBindings->Invalidate(SID_ATTR_ULSPACE);
777
0
                pBindings->Invalidate(SID_ATTR_PAGE_SIZE);
778
0
                pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION);
779
0
            }
780
781
0
            rReq.Done();
782
0
        }
783
0
        break;
784
0
        case SID_AUTO_STYLE:
785
0
            OSL_FAIL("use ScAutoStyleHint instead of SID_AUTO_STYLE");
786
0
            break;
787
0
        case SID_GET_COLORLIST:
788
0
            {
789
0
                const SvxColorListItem* pColItem = GetItem(SID_COLOR_TABLE);
790
0
                const XColorListRef& pList = pColItem->GetColorList();
791
0
                rReq.SetReturnValue(OfaXColorListItem(SID_GET_COLORLIST, pList));
792
0
            }
793
0
            break;
794
795
0
        case FID_CHG_RECORD:
796
0
            {
797
0
                ScDocument& rDoc = GetDocument();
798
                // get argument (recorded macro)
799
0
                const SfxBoolItem* pItem = rReq.GetArg(FID_CHG_RECORD);
800
0
                bool bDo = true;
801
802
                // desired state
803
0
                ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
804
0
                bool bActivateTracking = (pChangeTrack == nullptr);   // toggle
805
0
                if ( pItem )
806
0
                    bActivateTracking = pItem->GetValue();      // from argument
807
808
0
                if ( !bActivateTracking )
809
0
                {
810
0
                    if ( !pItem )
811
0
                    {
812
                        // no dialog on playing the macro
813
0
                        std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(),
814
0
                                                                   VclMessageType::Warning, VclButtonsType::YesNo,
815
0
                                                                   ScResId(STR_END_REDLINING)));
816
0
                        xWarn->set_default_response(RET_NO);
817
0
                        bDo = (xWarn->run() == RET_YES );
818
0
                    }
819
820
0
                    if ( bDo )
821
0
                    {
822
0
                        if (pChangeTrack)
823
0
                        {
824
0
                            if ( pChangeTrack->IsProtected() )
825
0
                                bDo = ExecuteChangeProtectionDialog();
826
0
                        }
827
0
                        if ( bDo )
828
0
                        {
829
0
                            rDoc.EndChangeTracking();
830
0
                            PostPaintGridAll();
831
0
                        }
832
0
                    }
833
0
                }
834
0
                else
835
0
                {
836
0
                    rDoc.StartChangeTracking();
837
0
                    ScChangeViewSettings aChangeViewSet;
838
0
                    aChangeViewSet.SetShowChanges(true);
839
0
                    rDoc.SetChangeViewSettings(aChangeViewSet);
840
0
                }
841
842
0
                if ( bDo )
843
0
                {
844
0
                    UpdateAcceptChangesDialog();
845
846
                    // invalidate slots
847
0
                    if (pBindings)
848
0
                        pBindings->InvalidateAll(false);
849
0
                    if ( !pItem )
850
0
                        rReq.AppendItem( SfxBoolItem( FID_CHG_RECORD, bActivateTracking ) );
851
0
                    rReq.Done();
852
0
                }
853
0
                else
854
0
                    rReq.Ignore();
855
0
            }
856
0
            break;
857
858
0
        case SID_CHG_PROTECT :
859
0
            {
860
0
                if ( ExecuteChangeProtectionDialog() )
861
0
                {
862
0
                    rReq.Done();
863
0
                    SetDocumentModified();
864
0
                }
865
0
                else
866
0
                    rReq.Ignore();
867
0
            }
868
0
            break;
869
870
0
        case SID_DOCUMENT_MERGE:
871
0
        case SID_DOCUMENT_COMPARE:
872
0
            {
873
0
                bool bDo = true;
874
0
                ScChangeTrack* pChangeTrack = m_pDocument->GetChangeTrack();
875
0
                if ( pChangeTrack && !m_pImpl->bIgnoreLostRedliningWarning )
876
0
                {
877
0
                    if ( nSlot == SID_DOCUMENT_COMPARE )
878
0
                    {   //! old changes trace will be lost
879
0
                        std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(),
880
0
                                                                   VclMessageType::Warning, VclButtonsType::YesNo,
881
0
                                                                   ScResId(STR_END_REDLINING)));
882
0
                        xWarn->set_default_response(RET_NO);
883
0
                        if (xWarn->run() == RET_YES)
884
0
                            bDo = ExecuteChangeProtectionDialog( true );
885
0
                        else
886
0
                            bDo = false;
887
0
                    }
888
0
                    else    // merge might reject some actions
889
0
                        bDo = ExecuteChangeProtectionDialog( true );
890
0
                }
891
0
                if ( !bDo )
892
0
                {
893
0
                    rReq.Ignore();
894
0
                    break;
895
0
                }
896
0
                SfxApplication* pApp = SfxGetpApp();
897
0
                const SfxPoolItem* pItem;
898
0
                const SfxStringItem* pFileNameItem(nullptr);
899
0
                SfxMedium* pMed = nullptr;
900
0
                if (pReqArgs)
901
0
                    pFileNameItem = pReqArgs->GetItemIfSet(SID_FILE_NAME);
902
0
                if (pFileNameItem)
903
0
                {
904
0
                    OUString aFileName = pFileNameItem->GetValue();
905
906
0
                    OUString aFilterName;
907
0
                    if (const SfxStringItem* pFilterItem = pReqArgs->GetItemIfSet(SID_FILTER_NAME))
908
0
                    {
909
0
                        aFilterName = pFilterItem->GetValue();
910
0
                    }
911
0
                    OUString aOptions;
912
0
                    if (const SfxStringItem* pOptionsItem = pReqArgs->GetItemIfSet(SID_FILE_FILTEROPTIONS))
913
0
                    {
914
0
                        aOptions = pOptionsItem->GetValue();
915
0
                    }
916
0
                    short nVersion = 0;
917
0
                    const SfxInt16Item* pInt16Item(nullptr);
918
0
                    if (pReqArgs->GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET)
919
0
                        pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem);
920
0
                    if (pInt16Item)
921
0
                    {
922
0
                        nVersion = pInt16Item->GetValue();
923
0
                    }
924
925
                    //  no filter specified -> detection
926
0
                    if (aFilterName.isEmpty())
927
0
                        ScDocumentLoader::GetFilterName( aFileName, aFilterName, aOptions, true, false );
928
929
                    //  filter name from dialog contains application prefix,
930
                    //  GetFilter needs name without the prefix.
931
0
                    ScDocumentLoader::RemoveAppPrefix( aFilterName );
932
933
0
                    std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
934
0
                    auto pSet = std::make_shared<SfxAllItemSet>( pApp->GetPool() );
935
0
                    if (!aOptions.isEmpty())
936
0
                        pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
937
0
                    if ( nVersion != 0 )
938
0
                        pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) );
939
0
                    pMed = new SfxMedium( aFileName, StreamMode::STD_READ, std::move(pFilter), std::move(pSet) );
940
0
                }
941
0
                else
942
0
                {
943
0
                    const sfx2::DocumentInserter::Mode mode { nSlot==SID_DOCUMENT_COMPARE
944
0
                        ? sfx2::DocumentInserter::Mode::Compare
945
0
                        : sfx2::DocumentInserter::Mode::Merge};
946
                    // start file dialog asynchronous
947
0
                    m_pImpl->bIgnoreLostRedliningWarning = true;
948
0
                    m_pImpl->pRequest.reset(new SfxRequest( rReq ));
949
0
                    m_pImpl->pDocInserter.reset();
950
951
0
                    ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
952
0
                    weld::Window* pParent = pViewSh ? pViewSh->GetFrameWeld() : nullptr;
953
0
                    m_pImpl->pDocInserter.reset( new ::sfx2::DocumentInserter(pParent,
954
0
                        ScDocShell::Factory().GetFactoryName(), mode ) );
955
0
                    m_pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) );
956
0
                    return ;
957
0
                }
958
959
                // now execute in earnest...
960
0
                SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() );
961
962
                // pOtherDocSh->DoClose() will be called explicitly later, but it is still more safe to use SfxObjectShellLock here
963
0
                rtl::Reference<ScDocShell> pOtherDocSh = new ScDocShell;
964
0
                pOtherDocSh->DoLoad( pMed );
965
0
                ErrCodeMsg nErr = pOtherDocSh->GetErrorCode();
966
0
                if (nErr)
967
0
                    ErrorHandler::HandleError( nErr );          // also warnings
968
969
0
                if ( !pOtherDocSh->GetErrorIgnoreWarning() )                 // only errors
970
0
                {
971
0
                    bool bHadTrack = ( m_pDocument->GetChangeTrack() != nullptr );
972
#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
973
                    sal_uLong nStart = 0;
974
                    if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack )
975
                    {
976
                        nStart = pChangeTrack->GetActionMax() + 1;
977
                    }
978
#endif
979
0
                    if ( nSlot == SID_DOCUMENT_COMPARE )
980
0
                        CompareDocument( pOtherDocSh->GetDocument() );
981
0
                    else
982
0
                        MergeDocument( pOtherDocSh->GetDocument() );
983
984
                    //  show "accept changes" dialog
985
                    //! get view for this document!
986
0
                    if ( !IsDocShared() )
987
0
                    {
988
0
                        SfxViewFrame* pViewFrm = SfxViewFrame::Current();
989
0
                        if ( pViewFrm )
990
0
                        {
991
0
                            pViewFrm->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId() ); //@51669
992
0
                        }
993
0
                        if ( pBindings )
994
0
                        {
995
0
                            pBindings->Invalidate( FID_CHG_ACCEPT );
996
0
                        }
997
0
                    }
998
999
0
                    rReq.SetReturnValue( SfxInt32Item( TypedWhichId<SfxInt32Item>(nSlot), 0 ) );        //! ???????
1000
0
                    rReq.Done();
1001
1002
0
                    if (!bHadTrack)         //  newly turned on -> show as well
1003
0
                    {
1004
0
                        ScChangeViewSettings* pOldSet = m_pDocument->GetChangeViewSettings();
1005
0
                        if ( !pOldSet || !pOldSet->ShowChanges() )
1006
0
                        {
1007
0
                            ScChangeViewSettings aChangeViewSet;
1008
0
                            aChangeViewSet.SetShowChanges(true);
1009
0
                            m_pDocument->SetChangeViewSettings(aChangeViewSet);
1010
0
                        }
1011
0
                    }
1012
#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
1013
                    else if ( nSlot == SID_DOCUMENT_MERGE && IsDocShared() && pChangeTrack )
1014
                    {
1015
                        sal_uLong nEnd = pChangeTrack->GetActionMax();
1016
                        if ( nEnd >= nStart )
1017
                        {
1018
                            // only show changes from merged document
1019
                            ScChangeViewSettings aChangeViewSet;
1020
                            aChangeViewSet.SetShowChanges( true );
1021
                            aChangeViewSet.SetShowAccepted( true );
1022
                            aChangeViewSet.SetHasActionRange();
1023
                            aChangeViewSet.SetTheActionRange( nStart, nEnd );
1024
                            m_pDocument->SetChangeViewSettings( aChangeViewSet );
1025
1026
                            // update view
1027
                            PostPaintExtras();
1028
                            PostPaintGridAll();
1029
                        }
1030
                    }
1031
#endif
1032
0
                }
1033
0
                pOtherDocSh->DoClose();     // delete happens with the Ref
1034
0
            }
1035
0
            break;
1036
1037
0
        case SID_DELETE_SCENARIO:
1038
0
            if (pReqArgs)
1039
0
            {
1040
0
                const SfxPoolItem* pItem;
1041
0
                if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
1042
0
                {
1043
0
                    if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
1044
0
                    {
1045
0
                        const OUString& aName = pStringItem->GetValue();
1046
0
                        SCTAB nTab;
1047
0
                        if (m_pDocument->GetTable( aName, nTab ))
1048
0
                        {
1049
                            //  move DeleteTable from viewfunc to docfunc!
1050
1051
0
                            ScTabViewShell* pSh = GetBestViewShell();
1052
0
                            if ( pSh )
1053
0
                            {
1054
                                //! omit SetTabNo in DeleteTable?
1055
0
                                SCTAB nDispTab = pSh->GetViewData().CurrentTabForData();
1056
0
                                pSh->DeleteTable( nTab );
1057
0
                                pSh->SetTabNo(nDispTab);
1058
0
                                rReq.Done();
1059
0
                            }
1060
0
                        }
1061
0
                    }
1062
0
                }
1063
0
            }
1064
0
            break;
1065
1066
0
        case SID_EDIT_SCENARIO:
1067
0
            {
1068
0
                const SfxPoolItem* pItem;
1069
0
                if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
1070
0
                {
1071
0
                    if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
1072
0
                    {
1073
0
                        OUString aName = pStringItem->GetValue();
1074
0
                        SCTAB nTab;
1075
0
                        if (m_pDocument->GetTable( aName, nTab ))
1076
0
                        {
1077
0
                            if (m_pDocument->IsScenario(nTab))
1078
0
                            {
1079
0
                                OUString aComment;
1080
0
                                Color aColor;
1081
0
                                ScScenarioFlags nFlags;
1082
0
                                m_pDocument->GetScenarioData( nTab, aComment, aColor, nFlags );
1083
1084
                                // Determine if the Sheet that the Scenario was created on
1085
                                // is protected. But first we need to find that Sheet.
1086
                                // Rewind back to the actual sheet.
1087
0
                                SCTAB nActualTab = nTab;
1088
0
                                do
1089
0
                                {
1090
0
                                    nActualTab--;
1091
0
                                }
1092
0
                                while(m_pDocument->IsScenario(nActualTab));
1093
0
                                bool bSheetProtected = m_pDocument->IsTabProtected(nActualTab);
1094
1095
0
                                ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1096
1097
0
                                ScopedVclPtr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(GetActiveDialogParent(), aName, true, bSheetProtected));
1098
0
                                pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags );
1099
0
                                if ( pNewDlg->Execute() == RET_OK )
1100
0
                                {
1101
0
                                    pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
1102
0
                                    ModifyScenario( nTab, aName, aComment, aColor, nFlags );
1103
0
                                    rReq.Done();
1104
0
                                }
1105
0
                            }
1106
0
                        }
1107
0
                    }
1108
0
                }
1109
0
            }
1110
0
            break;
1111
1112
0
        case SID_ATTR_YEAR2000 :
1113
0
        {
1114
0
            const SfxPoolItem* pItem;
1115
0
            if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
1116
0
            {
1117
0
                if (const SfxUInt16Item* pInt16Item = dynamic_cast<const SfxUInt16Item*>(pItem))
1118
0
                {
1119
0
                    sal_uInt16 nY2k = pInt16Item->GetValue();
1120
                    // set always to DocOptions, so that it is also saved for S050
1121
                    // (and all inquiries run up until now on it as well).
1122
                    // SetDocOptions propagates that to the NumberFormatter
1123
0
                    ScDocOptions aDocOpt( m_pDocument->GetDocOptions() );
1124
0
                    aDocOpt.SetYear2000( nY2k );
1125
0
                    m_pDocument->SetDocOptions( aDocOpt );
1126
                    // the FormShell shall notice it as well
1127
0
                    ScTabViewShell* pSh = GetBestViewShell();
1128
0
                    if ( pSh )
1129
0
                    {
1130
0
                        FmFormShell* pFSh = pSh->GetFormShell();
1131
0
                        if ( pFSh )
1132
0
                            pFSh->SetY2KState( nY2k );
1133
0
                    }
1134
0
                }
1135
0
            }
1136
0
        }
1137
0
        break;
1138
1139
#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
1140
        case SID_SHARE_DOC:
1141
            {
1142
                ScViewData* pViewData = GetViewData();
1143
                if ( !pViewData )
1144
                {
1145
                    rReq.Ignore();
1146
                    break;
1147
                }
1148
1149
                weld::Window* pWin = GetActiveDialogParent();
1150
                ScShareDocumentDlg aDlg(pWin, *pViewData);
1151
                if (aDlg.run() == RET_OK)
1152
                {
1153
                    bool bSetShared = aDlg.IsShareDocumentChecked();
1154
                    if ( bSetShared != IsDocShared() )
1155
                    {
1156
                        if ( bSetShared )
1157
                        {
1158
                            bool bContinue = true;
1159
                            if ( HasName() )
1160
                            {
1161
                                std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pWin,
1162
                                                                               VclMessageType::Question, VclButtonsType::YesNo,
1163
                                                                               ScResId(STR_DOC_WILLBESAVED)));
1164
                                xQueryBox->set_default_response(RET_YES);
1165
                                if (xQueryBox->run() == RET_NO)
1166
                                {
1167
                                    bContinue = false;
1168
                                }
1169
                            }
1170
                            if ( bContinue )
1171
                            {
1172
                                EnableSharedSettings( true );
1173
1174
                                ScModule* mod = ScModule::get();
1175
                                mod->SetInSharedDocSaving(true);
1176
                                if ( !SwitchToShared( true, true ) )
1177
                                {
1178
                                    // TODO/LATER: what should be done in case the switch has failed?
1179
                                    // for example in case the user has cancelled the saveAs operation
1180
                                }
1181
1182
                                mod->SetInSharedDocSaving(false);
1183
1184
                                InvalidateName();
1185
                                GetUndoManager()->Clear();
1186
1187
                                ScTabView* pTabView = pViewData->GetView();
1188
                                if ( pTabView )
1189
                                {
1190
                                    pTabView->UpdateLayerLocks();
1191
                                }
1192
                            }
1193
                        }
1194
                        else
1195
                        {
1196
                            uno::Reference< frame::XModel > xModel;
1197
                            try
1198
                            {
1199
                                // load shared file
1200
                                xModel.set( LoadSharedDocument(), uno::UNO_SET_THROW );
1201
                                uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
1202
1203
                                // check if shared flag is set in shared file
1204
                                bool bShared = false;
1205
                                ScModelObj* pDocObj = comphelper::getFromUnoTunnel<ScModelObj>( xModel );
1206
                                if ( pDocObj )
1207
                                {
1208
                                    ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pDocObj->GetEmbeddedObject() );
1209
                                    if ( pDocShell )
1210
                                    {
1211
                                        bShared = pDocShell->HasSharedXMLFlagSet();
1212
                                    }
1213
                                }
1214
1215
                                // #i87870# check if shared status was disabled and enabled again
1216
                                bool bOwnEntry = false;
1217
                                try
1218
                                {
1219
                                    ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
1220
                                    bOwnEntry = aControlFile.HasOwnEntry();
1221
                                }
1222
                                catch ( uno::Exception& )
1223
                                {
1224
                                }
1225
1226
                                if ( bShared && bOwnEntry )
1227
                                {
1228
                                    uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
1229
                                    if ( xStorable->isReadonly() )
1230
                                    {
1231
                                        xCloseable->close( true );
1232
1233
                                        OUString aUserName( ScResId( STR_UNKNOWN_USER ) );
1234
                                        try
1235
                                        {
1236
                                            ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
1237
                                            LockFileEntry aData = aLockFile.GetLockData();
1238
                                            if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
1239
                                            {
1240
                                                aUserName = aData[LockFileComponent::OOOUSERNAME];
1241
                                            }
1242
                                            else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() )
1243
                                            {
1244
                                                aUserName = aData[LockFileComponent::SYSUSERNAME];
1245
                                            }
1246
                                        }
1247
                                        catch ( uno::Exception& )
1248
                                        {
1249
                                        }
1250
                                        OUString aMessage( ScResId( STR_FILE_LOCKED_TRY_LATER ) );
1251
                                        aMessage = aMessage.replaceFirst( "%1", aUserName );
1252
1253
                                        std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin,
1254
                                                                                   VclMessageType::Warning, VclButtonsType::Ok,
1255
                                                                                   aMessage));
1256
                                        xWarn->run();
1257
                                    }
1258
                                    else
1259
                                    {
1260
                                        std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin,
1261
                                                                                   VclMessageType::Warning, VclButtonsType::YesNo,
1262
                                                                                   ScResId(STR_DOC_DISABLESHARED)));
1263
                                        xWarn->set_default_response(RET_YES);
1264
1265
                                        if (xWarn->run() == RET_YES)
1266
                                        {
1267
                                            xCloseable->close( true );
1268
1269
                                            if ( !SwitchToShared( false, true ) )
1270
                                            {
1271
                                                // TODO/LATER: what should be done in case the switch has failed?
1272
                                                // for example in case the user has cancelled the saveAs operation
1273
                                            }
1274
1275
                                            EnableSharedSettings( false );
1276
1277
                                            // Do *not* use dispatch mechanism in this place - we don't want others (extensions etc.) to intercept this.
1278
                                            GetModel()->store();
1279
1280
                                            ScTabView* pTabView = pViewData->GetView();
1281
                                            if ( pTabView )
1282
                                            {
1283
                                                pTabView->UpdateLayerLocks();
1284
                                            }
1285
                                        }
1286
                                        else
1287
                                        {
1288
                                            xCloseable->close( true );
1289
                                        }
1290
                                    }
1291
                                }
1292
                                else
1293
                                {
1294
                                    xCloseable->close( true );
1295
                                    std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin,
1296
                                                                               VclMessageType::Warning, VclButtonsType::Ok,
1297
                                                                               ScResId(STR_DOC_NOLONGERSHARED)));
1298
                                    xWarn->run();
1299
                                }
1300
                            }
1301
                            catch ( uno::Exception& )
1302
                            {
1303
                                TOOLS_WARN_EXCEPTION( "sc", "SID_SHARE_DOC" );
1304
                                ScModule::get()->SetInSharedDocSaving(false);
1305
1306
                                try
1307
                                {
1308
                                    uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
1309
                                    xClose->close( true );
1310
                                }
1311
                                catch ( uno::Exception& )
1312
                                {
1313
                                }
1314
                            }
1315
                        }
1316
                    }
1317
                }
1318
                rReq.Done();
1319
            }
1320
            break;
1321
#endif
1322
0
        case SID_OPEN_CALC:
1323
0
        {
1324
0
            ScViewData* pViewData = GetViewData();
1325
0
            if (pViewData)
1326
0
            {
1327
0
                SfxStringItem aApp(SID_DOC_SERVICE, u"com.sun.star.sheet.SpreadsheetDocument"_ustr);
1328
0
                SfxStringItem aTarget(SID_TARGETNAME, u"_blank"_ustr);
1329
0
                pViewData->GetDispatcher().ExecuteList(
1330
0
                    SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON,
1331
0
                    { &aApp, &aTarget });
1332
0
            }
1333
0
        }
1334
0
        break;
1335
0
        case SID_NOTEBOOKBAR:
1336
0
        {
1337
0
            const SfxStringItem* pFile = rReq.GetArg( SID_NOTEBOOKBAR );
1338
1339
0
            if ( pBindings && sfx2::SfxNotebookBar::IsActive() )
1340
0
                sfx2::SfxNotebookBar::ExecMethod(*pBindings, pFile ? pFile->GetValue() : u""_ustr);
1341
0
            else if ( pBindings )
1342
0
                sfx2::SfxNotebookBar::CloseMethod(*pBindings);
1343
0
        }
1344
0
        break;
1345
0
        case SID_LANGUAGE_STATUS:
1346
0
        {
1347
0
            OUString aLangText;
1348
0
            const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot);
1349
0
            if ( pItem )
1350
0
                aLangText = pItem->GetValue();
1351
1352
0
            if ( !aLangText.isEmpty() )
1353
0
            {
1354
0
                LanguageType eLang, eLatin, eCjk, eCtl;
1355
0
                static constexpr OUString aSelectionLangPrefix(u"Current_"_ustr);
1356
0
                static constexpr OUString aParagraphLangPrefix(u"Paragraph_"_ustr);
1357
0
                static constexpr OUString aDocLangPrefix(u"Default_"_ustr);
1358
1359
0
                bool bSelection = false;
1360
0
                bool bParagraph = false;
1361
1362
0
                ScDocument& rDoc = GetDocument();
1363
0
                rDoc.GetLanguage( eLatin, eCjk, eCtl );
1364
1365
0
                sal_Int32 nPos = 0;
1366
0
                if ( aLangText == "*" )
1367
0
                {
1368
0
                    if (ScTabViewShell* pSh = GetBestViewShell())
1369
0
                    {
1370
0
                        pSh->ExecuteCellFormatDlg(rReq, u"font"_ustr);
1371
0
                        pBindings->Invalidate(SID_LANGUAGE_STATUS);
1372
0
                    }
1373
0
                }
1374
0
                else if ( (nPos = aLangText.indexOf(aDocLangPrefix)) != -1 )
1375
0
                {
1376
0
                    aLangText = aLangText.replaceAt(nPos, aDocLangPrefix.getLength(), u"");
1377
1378
0
                    if ( aLangText == "LANGUAGE_NONE" )
1379
0
                    {
1380
0
                        eLang = LANGUAGE_NONE;
1381
0
                        SetLanguage(eLang, eCjk, eCtl);
1382
0
                    }
1383
0
                    else if ( aLangText == "RESET_LANGUAGES" )
1384
0
                    {
1385
0
                        ScModule::GetSpellSettings(eLang, eCjk, eCtl);
1386
0
                        SetLanguage(eLang, eCjk, eCtl);
1387
0
                    }
1388
0
                    else
1389
0
                    {
1390
0
                        eLang = SvtLanguageTable::GetLanguageType( aLangText );
1391
0
                        if ( eLang != LANGUAGE_DONTKNOW  && SvtLanguageOptions::GetScriptTypeOfLanguage(eLang) == SvtScriptType::LATIN )
1392
0
                        {
1393
0
                            SetLanguage(eLang, eCjk, eCtl);
1394
0
                        }
1395
0
                        else
1396
0
                        {
1397
0
                            eLang = eLatin;
1398
0
                        }
1399
0
                    }
1400
0
                }
1401
0
                else if (-1 != (nPos = aLangText.indexOf( aSelectionLangPrefix )))
1402
0
                {
1403
0
                    bSelection = true;
1404
0
                    aLangText = aLangText.replaceAt( nPos, aSelectionLangPrefix.getLength(), u"" );
1405
0
                }
1406
0
                else if (-1 != (nPos = aLangText.indexOf( aParagraphLangPrefix )))
1407
0
                {
1408
0
                    bParagraph = true;
1409
0
                    aLangText = aLangText.replaceAt( nPos, aParagraphLangPrefix.getLength(), u"" );
1410
0
                }
1411
1412
0
                if (bSelection)
1413
0
                {
1414
0
                    ScTabViewShell* pViewShell = GetBestViewShell();
1415
0
                    if (pViewShell)
1416
0
                    {
1417
0
                        const ScPatternAttr* pSelAttrs = pViewShell->GetSelectionPattern();
1418
0
                        if (pSelAttrs)
1419
0
                        {
1420
0
                            const SfxItemSet& rOldSet = pSelAttrs->GetItemSet();
1421
0
                            SfxItemPool* pItemPool = rOldSet.GetPool();
1422
0
                            auto pNewSet = std::make_shared<SfxItemSet>(*pItemPool);
1423
1424
0
                            if (aLangText == "LANGUAGE_NONE")
1425
0
                            {
1426
0
                                pNewSet->Put(SvxLanguageItem(LANGUAGE_NONE,
1427
0
                                                             pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_LANGUAGE)));
1428
0
                                pNewSet->Put(SvxLanguageItem(LANGUAGE_NONE,
1429
0
                                                             pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CJK_LANGUAGE)));
1430
0
                                pNewSet->Put(SvxLanguageItem(LANGUAGE_NONE,
1431
0
                                                             pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CTL_LANGUAGE)));
1432
0
                            }
1433
0
                            else
1434
0
                            {
1435
0
                                const LanguageType nLangType = SvtLanguageTable::GetLanguageType(aLangText);
1436
0
                                const SvtScriptType nScriptType =
1437
0
                                    SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType);
1438
0
                                if (nScriptType == SvtScriptType::LATIN)
1439
0
                                    pNewSet->Put(SvxLanguageItem(nLangType,
1440
0
                                                                 pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_LANGUAGE)));
1441
0
                                if (nScriptType == SvtScriptType::COMPLEX)
1442
0
                                    pNewSet->Put(SvxLanguageItem(nLangType,
1443
0
                                                                 pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CTL_LANGUAGE)));
1444
0
                                if (nScriptType == SvtScriptType::ASIAN)
1445
0
                                    pNewSet->Put(SvxLanguageItem(nLangType,
1446
0
                                                                 pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CJK_LANGUAGE)));
1447
0
                            }
1448
0
                            pViewShell->ApplyAttributes(*pNewSet, rOldSet);
1449
0
                            pBindings->Invalidate(SID_LANGUAGE_STATUS);
1450
0
                        }
1451
0
                    }
1452
0
                }
1453
0
                else if (bParagraph)
1454
0
                {
1455
0
                    ScViewData* pViewData = GetViewData();
1456
0
                    if (!pViewData)
1457
0
                        return;
1458
1459
0
                    EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart());
1460
0
                    if (!pEditView)
1461
0
                        return;
1462
1463
0
                    const LanguageType nLangToUse = SvtLanguageTable::GetLanguageType( aLangText );
1464
0
                    SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse );
1465
1466
0
                    SfxItemSet aAttrs = pEditView->getEditEngine().GetEmptyItemSet();
1467
0
                    if (nScriptType == SvtScriptType::LATIN)
1468
0
                        aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE ) );
1469
0
                    if (nScriptType == SvtScriptType::COMPLEX)
1470
0
                        aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CTL ) );
1471
0
                    if (nScriptType == SvtScriptType::ASIAN)
1472
0
                        aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CJK ) );
1473
0
                    ESelection aOldSel;
1474
0
                    if (bParagraph)
1475
0
                    {
1476
0
                        ESelection aSel = pEditView->GetSelection();
1477
0
                        aOldSel = aSel;
1478
0
                        aSel.start.nIndex = 0;
1479
0
                        aSel.end.nIndex = EE_TEXTPOS_MAX;
1480
0
                        pEditView->SetSelection( aSel );
1481
0
                    }
1482
1483
0
                    pEditView->SetAttribs( aAttrs );
1484
0
                    if (bParagraph)
1485
0
                        pEditView->SetSelection( aOldSel );
1486
0
                }
1487
0
                else if ( eLang != eLatin )
1488
0
                {
1489
0
                    if ( ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell() )
1490
0
                    {
1491
0
                        ScInputHandler* pInputHandler = ScModule::get()->GetInputHdl(pViewSh);
1492
0
                        if ( pInputHandler )
1493
0
                            pInputHandler->UpdateSpellSettings();
1494
1495
0
                        pViewSh->UpdateDrawTextOutliner();
1496
0
                    }
1497
1498
0
                    SetDocumentModified();
1499
0
                    Broadcast(SfxHint(SfxHintId::LanguageChanged));
1500
0
                    PostPaintGridAll();
1501
0
                }
1502
0
            }
1503
0
        }
1504
0
        break;
1505
0
        case SID_SPELLCHECK_IGNORE_ALL:
1506
0
        {
1507
0
            ScViewData* pViewData = GetViewData();
1508
0
            if (!pViewData)
1509
0
                return;
1510
1511
0
            EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart());
1512
0
            if (!pEditView)
1513
0
                return;
1514
1515
0
            OUString sIgnoreText;
1516
0
            const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
1517
0
            if (pItem2)
1518
0
                sIgnoreText = pItem2->GetValue();
1519
1520
0
            if(sIgnoreText == "Spelling")
1521
0
            {
1522
0
                ESelection aOldSel = pEditView->GetSelection();
1523
0
                pEditView->SpellIgnoreWord();
1524
0
                pEditView->SetSelection( aOldSel );
1525
0
            }
1526
0
        }
1527
0
        break;
1528
0
        case SID_SPELLCHECK_APPLY_SUGGESTION:
1529
0
        {
1530
0
            ScViewData* pViewData = GetViewData();
1531
0
            if (!pViewData)
1532
0
                return;
1533
1534
0
            EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart());
1535
0
            if (!pEditView)
1536
0
                return;
1537
1538
0
            OUString sApplyText;
1539
0
            const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
1540
0
            if (pItem2)
1541
0
                sApplyText = pItem2->GetValue();
1542
1543
0
            static constexpr OUString sSpellingRule(u"Spelling_"_ustr);
1544
0
            sal_Int32 nPos = 0;
1545
0
            if(-1 != (nPos = sApplyText.indexOf( sSpellingRule )))
1546
0
            {
1547
0
                sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), u"");
1548
0
                pEditView->InsertText( sApplyText );
1549
0
            }
1550
0
        }
1551
0
        break;
1552
0
        case SID_REFRESH_VIEW:
1553
0
        {
1554
0
            PostPaintGridAll();
1555
0
        }
1556
0
        break;
1557
0
        case SID_PROTECTPOS:
1558
0
        case SID_PROTECTSIZE:
1559
0
        {
1560
0
            ScTabViewShell* pViewShell = GetBestViewShell();
1561
0
            if (!pViewShell)
1562
0
                return;
1563
0
            ScDrawView* pScDrawView = pViewShell->GetViewData().GetScDrawView();
1564
0
            if (!pScDrawView)
1565
0
                return;
1566
1567
0
            const SdrMarkList& rMarkList = pScDrawView->GetMarkedObjectList();
1568
0
            assert ( rMarkList.GetMarkCount() == 1 );
1569
1570
0
            SdrObject* pGraphicObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
1571
0
            if (nSlot == SID_PROTECTSIZE)
1572
0
                pGraphicObj->SetResizeProtect(!pGraphicObj->IsResizeProtect());
1573
0
            else
1574
0
                pGraphicObj->SetMoveProtect(!pGraphicObj->IsMoveProtect());
1575
0
        }
1576
0
        break;
1577
0
        default:
1578
0
        {
1579
            // small (?) hack -> forwarding of the slots to TabViewShell
1580
0
            ScTabViewShell* pSh = GetBestViewShell();
1581
0
            if ( pSh )
1582
0
                pSh->Execute( rReq );
1583
#if HAVE_FEATURE_SCRIPTING
1584
            else
1585
                SbxBase::SetError( ERRCODE_BASIC_NO_ACTIVE_OBJECT );
1586
#endif
1587
0
        }
1588
0
    }
1589
0
}
1590
1591
void UpdateAcceptChangesDialog()
1592
0
{
1593
    //  update "accept changes" dialog
1594
    //! notify all views
1595
0
    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1596
0
    if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) )
1597
0
    {
1598
0
        SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT );
1599
0
        if ( pChild )
1600
0
            static_cast<ScAcceptChgDlgWrapper*>(pChild)->ReInitDlg();
1601
0
    }
1602
0
}
1603
1604
void ScDocShell::ExecuteChartSource(SfxRequest& rReq)
1605
0
{
1606
0
    const SfxItemSet* pReqArgs = rReq.GetArgs();
1607
0
    sal_uInt16 nSlot = rReq.GetSlot();
1608
0
    bool bUndo (m_pDocument->IsUndoEnabled());
1609
0
    if (!pReqArgs)
1610
0
    {
1611
0
        OSL_FAIL("SID_CHART_SOURCE without arguments");
1612
0
        return;
1613
0
    }
1614
1615
0
    ScDocument& rDoc = GetDocument();
1616
0
    const   SfxPoolItem* pItem;
1617
0
    OUString  aChartName, aRangeName;
1618
1619
0
    ScRange         aSingleRange;
1620
0
    ScRangeListRef  aRangeListRef;
1621
0
    bool            bMultiRange = false;
1622
1623
0
    bool bColHeaders = true;
1624
0
    bool bRowHeaders = true;
1625
0
    bool bColInit = false;
1626
0
    bool bRowInit = false;
1627
0
    bool bAddRange = (nSlot == SID_CHART_ADDSOURCE);
1628
1629
0
    if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_NAME ) )
1630
0
        aChartName = pChartItem->GetValue();
1631
1632
0
    if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_SOURCE ) )
1633
0
        aRangeName = pChartItem->GetValue();
1634
1635
0
    if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
1636
0
    {
1637
0
        bColHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1638
0
        bColInit = true;
1639
0
    }
1640
0
    if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
1641
0
    {
1642
0
        bRowHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1643
0
        bRowInit = true;
1644
0
    }
1645
1646
0
    ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0);
1647
0
    bool bValid = (aSingleRange.ParseAny(aRangeName, rDoc, aDetails) & ScRefFlags::VALID) != ScRefFlags::ZERO;
1648
0
    if (!bValid)
1649
0
    {
1650
0
        aRangeListRef = new ScRangeList;
1651
0
        aRangeListRef->Parse( aRangeName, rDoc, rDoc.GetAddressConvention());
1652
0
        if ( !aRangeListRef->empty() )
1653
0
        {
1654
0
            bMultiRange = true;
1655
0
            aSingleRange = aRangeListRef->front(); // for header
1656
0
            bValid = true;
1657
0
        }
1658
0
        else
1659
0
            aRangeListRef.clear();
1660
0
    }
1661
1662
0
    ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
1663
0
    if (!pViewSh || !bValid || aChartName.isEmpty() )
1664
0
    {
1665
0
        OSL_FAIL("UpdateChartArea: no ViewShell or wrong data");
1666
0
        rReq.Done();
1667
0
        return;
1668
0
    }
1669
1670
0
    weld::Window* pParent = pViewSh->GetFrameWeld();
1671
1672
0
    SCCOL nCol1 = aSingleRange.aStart.Col();
1673
0
    SCROW nRow1 = aSingleRange.aStart.Row();
1674
0
    SCCOL nCol2 = aSingleRange.aEnd.Col();
1675
0
    SCROW nRow2 = aSingleRange.aEnd.Row();
1676
0
    SCTAB nTab = aSingleRange.aStart.Tab();
1677
1678
    //! limit always or not at all ???
1679
0
    if (!bMultiRange)
1680
0
        m_pDocument->LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );
1681
1682
    // Dialog for column/row headers
1683
0
    if ( !bAddRange && ( !bColInit || !bRowInit ) )
1684
0
    {
1685
0
        ScChartPositioner aChartPositioner( *m_pDocument, nTab, nCol1,nRow1, nCol2,nRow2 );
1686
0
        if (!bColInit)
1687
0
            bColHeaders = aChartPositioner.HasColHeaders();
1688
0
        if (!bRowInit)
1689
0
            bRowHeaders = aChartPositioner.HasRowHeaders();
1690
1691
0
        auto xRequest = std::make_shared<SfxRequest>(rReq);
1692
0
        rReq.Ignore(); // the 'old' request is not relevant any more
1693
0
        ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1694
0
        VclPtr<AbstractScColRowLabelDlg> pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders));
1695
0
        pDlg->StartExecuteAsync(
1696
0
            [this, pDlg, xRequest=std::move(xRequest), bUndo, bMultiRange,
1697
0
             aChartName, aRangeListRef=std::move(aRangeListRef), bAddRange,
1698
0
             nCol1, nRow1, nCol2, nRow2, nTab] (sal_Int32 nResult)->void
1699
0
            {
1700
0
                if (nResult == RET_OK)
1701
0
                {
1702
0
                    bool bColHeaders2 = pDlg->IsRow();
1703
0
                    bool bRowHeaders2 = pDlg->IsCol();
1704
1705
0
                    xRequest->AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders2));
1706
0
                    xRequest->AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders2));
1707
0
                    ExecuteChartSourcePost(bUndo, bMultiRange,
1708
0
                        aChartName, aRangeListRef, bColHeaders2, bRowHeaders2, bAddRange,
1709
0
                        nCol1, nRow1, nCol2, nRow2, nTab);
1710
0
                }
1711
0
                pDlg->disposeOnce();
1712
0
                xRequest->Done();
1713
0
            }
1714
0
        );
1715
0
    }
1716
0
    else
1717
0
    {
1718
0
        ExecuteChartSourcePost(bUndo, bMultiRange,
1719
0
            aChartName, aRangeListRef, bColHeaders, bRowHeaders, bAddRange,
1720
0
            nCol1, nRow1,nCol2, nRow2, nTab);
1721
0
        rReq.Done();
1722
0
    }
1723
0
}
1724
1725
void ScDocShell::ExecuteChartSourcePost(bool bUndo, bool bMultiRange,
1726
    const OUString& rChartName, const ScRangeListRef& rRangeListRef,
1727
    bool bColHeaders, bool bRowHeaders, bool bAddRange,
1728
    SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab )
1729
0
{
1730
0
    if (bMultiRange)
1731
0
    {
1732
0
        if (bUndo)
1733
0
        {
1734
0
            GetUndoManager()->AddUndoAction(
1735
0
                std::make_unique<ScUndoChartData>( *this, rChartName, rRangeListRef,
1736
0
                                        bColHeaders, bRowHeaders, bAddRange ) );
1737
0
        }
1738
0
        m_pDocument->UpdateChartArea( rChartName, rRangeListRef,
1739
0
                                    bColHeaders, bRowHeaders, bAddRange );
1740
0
    }
1741
0
    else
1742
0
    {
1743
0
        ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
1744
0
        if (bUndo)
1745
0
        {
1746
0
            GetUndoManager()->AddUndoAction(
1747
0
                std::make_unique<ScUndoChartData>( *this, rChartName, aNewRange,
1748
0
                                        bColHeaders, bRowHeaders, bAddRange ) );
1749
0
        }
1750
0
        m_pDocument->UpdateChartArea( rChartName, aNewRange,
1751
0
                                    bColHeaders, bRowHeaders, bAddRange );
1752
0
    }
1753
0
}
1754
1755
bool ScDocShell::ExecuteChangeProtectionDialog( bool bJustQueryIfProtected )
1756
0
{
1757
0
    bool bDone = false;
1758
0
    ScChangeTrack* pChangeTrack = m_pDocument->GetChangeTrack();
1759
0
    if ( pChangeTrack )
1760
0
    {
1761
0
        bool bProtected = pChangeTrack->IsProtected();
1762
0
        if ( bJustQueryIfProtected && !bProtected )
1763
0
            return true;
1764
1765
0
        OUString aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) );
1766
0
        OUString aText( ScResId( SCSTR_PASSWORD ) );
1767
0
        OUString aPassword;
1768
1769
0
        weld::Window* pWin = ScDocShell::GetActiveDialogParent();
1770
0
        SfxPasswordDialog aDlg(pWin, &aText);
1771
0
        aDlg.set_title(aTitle);
1772
0
        aDlg.SetMinLen(1);
1773
0
        aDlg.set_help_id(GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand());
1774
0
        aDlg.SetEditHelpId( HID_CHG_PROTECT );
1775
0
        if ( !bProtected )
1776
0
            aDlg.ShowExtras(SfxShowExtras::CONFIRM);
1777
0
        if (aDlg.run() == RET_OK)
1778
0
            aPassword = aDlg.GetPassword();
1779
1780
0
        if (!aPassword.isEmpty())
1781
0
        {
1782
0
            if ( bProtected )
1783
0
            {
1784
0
                if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) )
1785
0
                {
1786
0
                    if ( bJustQueryIfProtected )
1787
0
                        bDone = true;
1788
0
                    else
1789
0
                        pChangeTrack->SetProtection( {} );
1790
0
                }
1791
0
                else
1792
0
                {
1793
0
                    std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin,
1794
0
                                                                  VclMessageType::Info, VclButtonsType::Ok,
1795
0
                                                                  ScResId(SCSTR_WRONGPASSWORD)));
1796
0
                    xInfoBox->run();
1797
0
                }
1798
0
            }
1799
0
            else
1800
0
            {
1801
0
                css::uno::Sequence< sal_Int8 > aPass;
1802
0
                SvPasswordHelper::GetHashPassword( aPass, aPassword );
1803
0
                pChangeTrack->SetProtection( aPass );
1804
0
            }
1805
0
            if ( bProtected != pChangeTrack->IsProtected() )
1806
0
            {
1807
0
                UpdateAcceptChangesDialog();
1808
0
                bDone = true;
1809
0
            }
1810
0
        }
1811
0
    }
1812
0
    else if ( bJustQueryIfProtected )
1813
0
        bDone = true;
1814
0
    return bDone;
1815
0
}
1816
1817
void ScDocShell::DoRecalc( bool bApi )
1818
0
{
1819
0
    if (m_pDocument->IsInDocShellRecalc())
1820
0
    {
1821
0
        SAL_WARN("sc","ScDocShell::DoRecalc tries re-entering while in Recalc; probably Forms->BASIC->Dispatcher.");
1822
0
        return;
1823
0
    }
1824
0
    ScDocShellRecalcGuard aGuard(*m_pDocument);
1825
0
    bool bDone = false;
1826
0
    ScTabViewShell* pSh = GetBestViewShell();
1827
0
    ScInputHandler* pHdl = (pSh ? ScModule::get()->GetInputHdl(pSh) : nullptr);
1828
0
    if ( pSh )
1829
0
    {
1830
0
        if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi )
1831
0
        {
1832
0
            pHdl->FormulaPreview();     // partial result as QuickHelp
1833
0
            bDone = true;
1834
0
        }
1835
0
        else
1836
0
        {
1837
0
            ScTabView::UpdateInputLine();     // InputEnterHandler
1838
0
            pSh->UpdateInputHandler();
1839
0
        }
1840
0
    }
1841
0
    if (bDone)                         // otherwise re-calculate document
1842
0
        return;
1843
1844
0
    weld::WaitObject aWaitObj( GetActiveDialogParent() );
1845
0
    if ( pHdl )
1846
0
    {
1847
        // tdf97897 set current cell to Dirty to force recalculation of cell
1848
0
        ScFormulaCell* pFC = m_pDocument->GetFormulaCell( pHdl->GetCursorPos());
1849
0
        if (pFC)
1850
0
            pFC->SetDirty();
1851
0
    }
1852
0
    m_pDocument->CalcFormulaTree();
1853
0
    if ( pSh )
1854
0
        pSh->UpdateCharts(true);
1855
1856
0
    m_pDocument->BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
1857
1858
    //  If there are charts, then paint everything, so that PostDataChanged
1859
    //  and the charts do not come one after the other and parts are painted twice.
1860
1861
0
    ScChartListenerCollection* pCharts = m_pDocument->GetChartListenerCollection();
1862
0
    if ( pCharts && pCharts->hasListeners() )
1863
0
        PostPaintGridAll();
1864
0
    else
1865
0
        PostDataChanged();
1866
0
}
1867
1868
void ScDocShell::DoHardRecalc()
1869
7.05k
{
1870
7.05k
    if (m_pDocument->IsInDocShellRecalc())
1871
0
    {
1872
0
        SAL_WARN("sc","ScDocShell::DoHardRecalc tries re-entering while in Recalc; probably Forms->BASIC->Dispatcher.");
1873
0
        return;
1874
0
    }
1875
7.05k
    auto start = std::chrono::steady_clock::now();
1876
7.05k
    ScDocShellRecalcGuard aGuard(*m_pDocument);
1877
7.05k
    weld::WaitObject aWaitObj( GetActiveDialogParent() );
1878
7.05k
    ScTabViewShell* pSh = GetBestViewShell();
1879
7.05k
    if ( pSh )
1880
0
    {
1881
0
        ScTabView::UpdateInputLine();     // InputEnterHandler
1882
0
        pSh->UpdateInputHandler();
1883
0
    }
1884
7.05k
    m_pDocument->CalcAll();
1885
7.05k
    GetDocFunc().DetectiveRefresh();    // creates own Undo
1886
7.05k
    if ( pSh )
1887
0
        pSh->UpdateCharts(true);
1888
1889
    // set notification flags for "calculate" event (used in SfxHintId::DataChanged broadcast)
1890
    // (might check for the presence of any formulas on each sheet)
1891
7.05k
    SCTAB nTabCount = m_pDocument->GetTableCount();
1892
7.05k
    if (m_pDocument->HasAnySheetEventScript( ScSheetEventId::CALCULATE, true )) // search also for VBA handler
1893
0
        for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1894
0
            m_pDocument->SetCalcNotification(nTab);
1895
1896
    // CalcAll doesn't broadcast value changes, so SfxHintId::ScCalcAll is broadcasted globally
1897
    // in addition to SfxHintId::DataChanged.
1898
7.05k
    m_pDocument->BroadcastUno( SfxHint( SfxHintId::ScCalcAll ) );
1899
7.05k
    m_pDocument->BroadcastUno( SfxHint( SfxHintId::DataChanged ) );
1900
1901
    // use hard recalc also to disable stream-copying of all sheets
1902
    // (somewhat consistent with charts)
1903
23.1k
    for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1904
16.1k
        m_pDocument->SetStreamValid(nTab, false);
1905
1906
7.05k
    PostPaintGridAll();
1907
7.05k
    auto end = std::chrono::steady_clock::now();
1908
7.05k
    SAL_INFO("sc.timing", "ScDocShell::DoHardRecalc(): took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms");
1909
7.05k
}
1910
1911
void ScDocShell::DoAutoStyle( const ScRange& rRange, const OUString& rStyle )
1912
0
{
1913
0
    ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool();
1914
0
    ScStyleSheet* pStyleSheet = pStylePool->FindAutoStyle(rStyle);
1915
0
    if (!pStyleSheet)
1916
0
        return;
1917
1918
0
    OSL_ENSURE(rRange.aStart.Tab() == rRange.aEnd.Tab(),
1919
0
                    "DoAutoStyle with several tables");
1920
0
    SCTAB nTab = rRange.aStart.Tab();
1921
0
    SCCOL nStartCol = rRange.aStart.Col();
1922
0
    SCROW nStartRow = rRange.aStart.Row();
1923
0
    SCCOL nEndCol = rRange.aEnd.Col();
1924
0
    SCROW nEndRow = rRange.aEnd.Row();
1925
0
    m_pDocument->ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
1926
0
    m_pDocument->ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
1927
0
    PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PaintPartFlags::Grid );
1928
0
}
1929
1930
void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )
1931
59.1k
{
1932
59.1k
    SfxHintId nId = rHint.GetId();
1933
59.1k
    const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet();
1934
59.1k
    if (!pStyle)
1935
0
        return;
1936
1937
59.1k
    if ( pStyle->GetFamily() == SfxStyleFamily::Page )
1938
10.9k
    {
1939
10.9k
        if ( nId == SfxHintId::StyleSheetModified || nId == SfxHintId::StyleSheetModifiedExtended )
1940
10.9k
        {
1941
10.9k
            ScDocShellModificator aModificator( *this );
1942
1943
10.9k
            const OUString& aNewName = pStyle->GetName();
1944
10.9k
            OUString aOldName = aNewName;
1945
10.9k
            if ( nId == SfxHintId::StyleSheetModifiedExtended )
1946
0
            {
1947
0
                const SfxStyleSheetModifiedHint& rExtendedHint = static_cast<const SfxStyleSheetModifiedHint&>(rHint); // name changed?
1948
0
                aOldName = rExtendedHint.GetOldName();
1949
0
            }
1950
10.9k
            if ( aNewName != aOldName )
1951
0
                m_pDocument->RenamePageStyleInUse( aOldName, aNewName );
1952
1953
10.9k
            SCTAB nTabCount = m_pDocument->GetTableCount();
1954
22.4k
            for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1955
11.4k
                if (m_pDocument->GetPageStyle(nTab) == aNewName)   // already adjusted to new
1956
5.47k
                {
1957
5.47k
                    m_pDocument->PageStyleModified( nTab, aNewName );
1958
5.47k
                    ScPrintFunc aPrintFunc( *this, GetPrinter(), nTab );
1959
5.47k
                    aPrintFunc.UpdatePages();
1960
5.47k
                }
1961
1962
10.9k
            aModificator.SetDocumentModified();
1963
1964
10.9k
            if (nId == SfxHintId::StyleSheetModifiedExtended)
1965
0
            {
1966
0
                SfxBindings* pBindings = GetViewBindings();
1967
0
                if (pBindings)
1968
0
                {
1969
0
                    pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1970
0
                    pBindings->Invalidate( SID_STYLE_FAMILY4 );
1971
0
                    pBindings->Invalidate( FID_RESET_PRINTZOOM );
1972
0
                    pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1973
0
                    pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1974
0
                }
1975
0
            }
1976
10.9k
        }
1977
10.9k
    }
1978
48.1k
    else if ( pStyle->GetFamily() == SfxStyleFamily::Para )
1979
29.6k
    {
1980
29.6k
        if (nId == SfxHintId::StyleSheetModifiedExtended)
1981
0
        {
1982
0
            const SfxStyleSheetModifiedHint& rExtendedHint = static_cast<const SfxStyleSheetModifiedHint&>(rHint);
1983
0
            const OUString& aNewName = pStyle->GetName();
1984
0
            const OUString& aOldName = rExtendedHint.GetOldName();
1985
0
            if ( aNewName != aOldName )
1986
0
            {
1987
0
                for(SCTAB i = 0; i < m_pDocument->GetTableCount(); ++i)
1988
0
                {
1989
0
                    ScConditionalFormatList* pList = m_pDocument->GetCondFormList(i);
1990
0
                    if (pList)
1991
0
                        pList->RenameCellStyle( aOldName,aNewName );
1992
0
                }
1993
0
            }
1994
0
        }
1995
29.6k
    }
1996
1997
    //  everything else goes via slots...
1998
59.1k
}
1999
2000
//  like in printfun.cxx
2001
0
#define ZOOM_MIN    10
2002
2003
void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages )
2004
0
{
2005
0
    OUString aStyleName = m_pDocument->GetPageStyle( nTab );
2006
0
    ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool();
2007
0
    SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
2008
0
    OSL_ENSURE( pStyleSheet, "PageStyle not found" );
2009
0
    if ( !pStyleSheet )
2010
0
        return;
2011
2012
0
    ScDocShellModificator aModificator( *this );
2013
2014
0
    SfxItemSet& rSet = pStyleSheet->GetItemSet();
2015
0
    const bool bUndo(m_pDocument->IsUndoEnabled());
2016
0
    if (bUndo)
2017
0
    {
2018
0
        sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
2019
0
        sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
2020
0
        GetUndoManager()->AddUndoAction( std::make_unique<ScUndoPrintZoom>(
2021
0
                        *this, nTab, nOldScale, nOldPages, nScale, nPages ) );
2022
0
    }
2023
2024
0
    rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
2025
0
    rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
2026
2027
0
    ScPrintFunc aPrintFunc( *this, GetPrinter(), nTab );
2028
0
    aPrintFunc.UpdatePages();
2029
0
    aModificator.SetDocumentModified();
2030
2031
0
    SfxBindings* pBindings = GetViewBindings();
2032
0
    if (pBindings)
2033
0
        pBindings->Invalidate( FID_RESET_PRINTZOOM );
2034
0
}
2035
2036
bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
2037
0
{
2038
0
    bool bChange = false;
2039
0
    SCTAB nTab = rRange.aStart.Tab();
2040
2041
0
    OUString aStyleName = m_pDocument->GetPageStyle( nTab );
2042
0
    ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool();
2043
0
    SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page );
2044
0
    OSL_ENSURE( pStyleSheet, "PageStyle not found" );
2045
0
    if ( pStyleSheet )
2046
0
    {
2047
0
        SfxItemSet& rSet = pStyleSheet->GetItemSet();
2048
0
        bool bHeaders = rSet.Get(ATTR_PAGE_HEADERS).GetValue();
2049
0
        sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue();
2050
0
        sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
2051
0
        std::optional<ScRange> oRepeatCol = m_pDocument->GetRepeatColRange( nTab );
2052
0
        std::optional<ScRange> oRepeatRow = m_pDocument->GetRepeatRowRange( nTab );
2053
2054
        //  calculate needed scaling for selection
2055
2056
0
        sal_uInt16 nNewScale = nOldScale;
2057
2058
0
        tools::Long nBlkTwipsX = 0;
2059
0
        if (bHeaders)
2060
0
            nBlkTwipsX += PRINT_HEADER_WIDTH;
2061
0
        SCCOL nStartCol = rRange.aStart.Col();
2062
0
        SCCOL nEndCol = rRange.aEnd.Col();
2063
0
        if ( oRepeatCol && nStartCol >= oRepeatCol->aStart.Col() )
2064
0
        {
2065
0
            for (SCCOL i=oRepeatCol->aStart.Col(); i<=oRepeatCol->aEnd.Col(); i++ )
2066
0
                nBlkTwipsX += m_pDocument->GetColWidth( i, nTab );
2067
0
            if ( nStartCol <= oRepeatCol->aEnd.Col() )
2068
0
                nStartCol = oRepeatCol->aEnd.Col() + 1;
2069
0
        }
2070
        // legacy compilers' own scope for i
2071
0
        {
2072
0
            for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
2073
0
                nBlkTwipsX += m_pDocument->GetColWidth( i, nTab );
2074
0
        }
2075
2076
0
        tools::Long nBlkTwipsY = 0;
2077
0
        if (bHeaders)
2078
0
            nBlkTwipsY += PRINT_HEADER_HEIGHT;
2079
0
        SCROW nStartRow = rRange.aStart.Row();
2080
0
        SCROW nEndRow = rRange.aEnd.Row();
2081
0
        if ( oRepeatRow && nStartRow >= oRepeatRow->aStart.Row() )
2082
0
        {
2083
0
            nBlkTwipsY += m_pDocument->GetRowHeight( oRepeatRow->aStart.Row(),
2084
0
                    oRepeatRow->aEnd.Row(), nTab );
2085
0
            if ( nStartRow <= oRepeatRow->aEnd.Row() )
2086
0
                nStartRow = oRepeatRow->aEnd.Row() + 1;
2087
0
        }
2088
0
        nBlkTwipsY += m_pDocument->GetRowHeight( nStartRow, nEndRow, nTab );
2089
2090
0
        Size aPhysPage;
2091
0
        tools::Long nHdr, nFtr;
2092
0
        ScPrintFunc aOldPrFunc( *this, GetPrinter(), nTab );
2093
0
        aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
2094
0
        nBlkTwipsY += nHdr + nFtr;
2095
2096
0
        if ( nBlkTwipsX == 0 )      // hidden columns/rows may lead to 0
2097
0
            nBlkTwipsX = 1;
2098
0
        if ( nBlkTwipsY == 0 )
2099
0
            nBlkTwipsY = 1;
2100
2101
0
        tools::Long nNeeded = std::min( aPhysPage.Width()  * 100 / nBlkTwipsX,
2102
0
                            aPhysPage.Height() * 100 / nBlkTwipsY );
2103
0
        if ( nNeeded < ZOOM_MIN )
2104
0
            nNeeded = ZOOM_MIN;         // boundary
2105
0
        if ( nNeeded < static_cast<tools::Long>(nNewScale) )
2106
0
            nNewScale = static_cast<sal_uInt16>(nNeeded);
2107
2108
0
        bChange = ( nNewScale != nOldScale || nOldPages != 0 );
2109
0
        if ( bChange )
2110
0
            SetPrintZoom( nTab, nNewScale, 0 );
2111
0
    }
2112
0
    return bChange;
2113
0
}
2114
2115
void ScDocShell::PageStyleModified( std::u16string_view rStyleName, bool bApi )
2116
238k
{
2117
238k
    ScDocShellModificator aModificator( *this );
2118
2119
238k
    SCTAB nTabCount = m_pDocument->GetTableCount();
2120
238k
    SCTAB nUseTab = MAXTAB+1;
2121
830k
    for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
2122
592k
        if ( m_pDocument->GetPageStyle(nTab) == rStyleName &&
2123
45.8k
                ( !bApi || m_pDocument->GetPageSize(nTab).Width() ) )
2124
23.5k
            nUseTab = nTab;
2125
                                // at bApi only if breaks already shown
2126
2127
238k
    if (ValidTab(nUseTab))      // not used -> nothing to do
2128
23.5k
    {
2129
23.5k
        bool bWarn = false;
2130
2131
23.5k
        ScPrintFunc aPrintFunc( *this, GetPrinter(), nUseTab );  //! cope without CountPages
2132
23.5k
        if (!aPrintFunc.UpdatePages())                          //  sets breaks on all tabs
2133
0
            bWarn = true;
2134
2135
23.5k
        if (bWarn && !bApi)
2136
0
        {
2137
0
            weld::Window* pWin = GetActiveDialogParent();
2138
0
            weld::WaitObject aWaitOff(pWin);
2139
0
            std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin,
2140
0
                                                          VclMessageType::Info, VclButtonsType::Ok,
2141
0
                                                          ScResId(STR_PRINT_INVALID_AREA)));
2142
0
            xInfoBox->run();
2143
0
        }
2144
23.5k
    }
2145
2146
238k
    aModificator.SetDocumentModified();
2147
2148
238k
    SfxBindings* pBindings = GetViewBindings();
2149
238k
    if (pBindings)
2150
0
    {
2151
0
        pBindings->Invalidate( FID_RESET_PRINTZOOM );
2152
0
        pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
2153
0
        pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
2154
0
    }
2155
238k
}
2156
2157
void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller,
2158
                                   SfxRequest&   rReq,
2159
                                   SCTAB         nCurTab )
2160
0
{
2161
0
    const SfxItemSet* pReqArgs = rReq.GetArgs();
2162
2163
0
    switch ( rReq.GetSlot() )
2164
0
    {
2165
0
        case SID_STATUS_PAGESTYLE:  // click on StatusBar control
2166
0
        case SID_FORMATPAGE:
2167
0
            {
2168
0
                if ( pReqArgs == nullptr )
2169
0
                {
2170
0
                    OUString aOldName = m_pDocument->GetPageStyle( nCurTab );
2171
0
                    ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool();
2172
0
                    SfxStyleSheetBase* pStyleSheet
2173
0
                        = pStylePool->Find( aOldName, SfxStyleFamily::Page );
2174
2175
0
                    OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
2176
2177
0
                    if ( pStyleSheet )
2178
0
                    {
2179
0
                        auto xOldData = std::make_shared<ScStyleSaveData>();
2180
0
                        const bool bUndo(m_pDocument->IsUndoEnabled());
2181
0
                        if (bUndo)
2182
0
                            xOldData->InitFromStyle(pStyleSheet);
2183
2184
0
                        SfxItemSet&     rStyleSet = pStyleSheet->GetItemSet();
2185
0
                        rStyleSet.MergeRange( XATTR_FILL_FIRST, XATTR_FILL_LAST );
2186
2187
0
                        ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2188
2189
0
                        VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScStyleDlg(GetActiveDialogParent(), *pStyleSheet, true));
2190
2191
0
                        auto xRequest = std::make_shared<SfxRequest>(rReq);
2192
0
                        rReq.Ignore(); // the 'old' request is not relevant any more
2193
0
                        pDlg->StartExecuteAsync([this, pDlg, xRequest=std::move(xRequest), pStyleSheet,
2194
0
                                                 xOldData=std::move(xOldData), aOldName, &rStyleSet,
2195
0
                                                 nCurTab, &rCaller, bUndo](sal_Int32 nResult) {
2196
0
                            if ( nResult == RET_OK )
2197
0
                            {
2198
0
                                const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
2199
2200
0
                                weld::WaitObject aWait( GetActiveDialogParent() );
2201
2202
0
                                OUString aNewName = pStyleSheet->GetName();
2203
0
                                if ( aNewName != aOldName &&
2204
0
                                    m_pDocument->RenamePageStyleInUse( aOldName, aNewName ) )
2205
0
                                {
2206
0
                                    SfxBindings* pBindings = GetViewBindings();
2207
0
                                    if (pBindings)
2208
0
                                    {
2209
0
                                        pBindings->Invalidate( SID_STATUS_PAGESTYLE );
2210
0
                                        pBindings->Invalidate( FID_RESET_PRINTZOOM );
2211
0
                                    }
2212
0
                                }
2213
2214
0
                                if ( pOutSet )
2215
0
                                    m_pDocument->ModifyStyleSheet( *pStyleSheet, *pOutSet );
2216
2217
                                // memorizing for GetState():
2218
0
                                GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );
2219
0
                                rCaller.GetViewFrame().GetBindings().Invalidate( SID_HFEDIT );
2220
2221
0
                                ScStyleSaveData aNewData;
2222
0
                                aNewData.InitFromStyle( pStyleSheet );
2223
0
                                if (bUndo)
2224
0
                                {
2225
0
                                    GetUndoManager()->AddUndoAction(
2226
0
                                            std::make_unique<ScUndoModifyStyle>( *this, SfxStyleFamily::Page,
2227
0
                                                        *xOldData, aNewData ) );
2228
0
                                }
2229
2230
0
                                PageStyleModified( aNewName, false );
2231
0
                                xRequest->Done();
2232
0
                            }
2233
0
                            pDlg->disposeOnce();
2234
0
                        });
2235
0
                    }
2236
0
                }
2237
0
            }
2238
0
            break;
2239
2240
0
        case SID_HFEDIT:
2241
0
            {
2242
0
                if ( pReqArgs == nullptr )
2243
0
                {
2244
0
                    OUString aStr( m_pDocument->GetPageStyle( nCurTab ) );
2245
2246
0
                    ScStyleSheetPool* pStylePool
2247
0
                        = m_pDocument->GetStyleSheetPool();
2248
2249
0
                    SfxStyleSheetBase* pStyleSheet
2250
0
                        = pStylePool->Find( aStr, SfxStyleFamily::Page );
2251
2252
0
                    OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
2253
2254
0
                    if ( pStyleSheet )
2255
0
                    {
2256
0
                        SfxItemSet&  rStyleSet = pStyleSheet->GetItemSet();
2257
2258
0
                        SvxPageUsage eUsage = rStyleSet.Get( ATTR_PAGE ).GetPageUsage();
2259
0
                        bool bShareHeader = rStyleSet
2260
0
                                                    .Get(ATTR_PAGE_HEADERSET)
2261
0
                                                    .GetItemSet()
2262
0
                                                    .Get(ATTR_PAGE_SHARED)
2263
0
                                                    .GetValue();
2264
0
                        bool bShareFooter = rStyleSet
2265
0
                                                    .Get(ATTR_PAGE_FOOTERSET)
2266
0
                                                    .GetItemSet()
2267
0
                                                    .Get(ATTR_PAGE_SHARED)
2268
0
                                                    .GetValue();
2269
0
                        sal_uInt16 nResId = 0;
2270
2271
0
                        switch ( eUsage )
2272
0
                        {
2273
0
                            case SvxPageUsage::Left:
2274
0
                            case SvxPageUsage::Right:
2275
0
                            {
2276
0
                                if ( m_bHeaderOn && m_bFooterOn )
2277
0
                                    nResId = RID_SCDLG_HFEDIT;
2278
0
                                else if ( SvxPageUsage::Right == eUsage )
2279
0
                                {
2280
0
                                    if ( !m_bHeaderOn && m_bFooterOn )
2281
0
                                        nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
2282
0
                                    else if ( m_bHeaderOn && !m_bFooterOn )
2283
0
                                        nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
2284
0
                                }
2285
0
                                else
2286
0
                                {
2287
                                    //  #69193a# respect "shared" setting
2288
0
                                    if ( !m_bHeaderOn && m_bFooterOn )
2289
0
                                        nResId = bShareFooter ?
2290
0
                                                    RID_SCDLG_HFEDIT_RIGHTFOOTER :
2291
0
                                                    RID_SCDLG_HFEDIT_LEFTFOOTER;
2292
0
                                    else if ( m_bHeaderOn && !m_bFooterOn )
2293
0
                                        nResId = bShareHeader ?
2294
0
                                                    RID_SCDLG_HFEDIT_RIGHTHEADER :
2295
0
                                                    RID_SCDLG_HFEDIT_LEFTHEADER;
2296
0
                                }
2297
0
                            }
2298
0
                            break;
2299
2300
0
                            case SvxPageUsage::Mirror:
2301
0
                            case SvxPageUsage::All:
2302
0
                            default:
2303
0
                            {
2304
0
                                if ( !bShareHeader && !bShareFooter )
2305
0
                                {
2306
0
                                    if ( m_bHeaderOn && m_bFooterOn )
2307
0
                                        nResId = RID_SCDLG_HFEDIT_ALL;
2308
0
                                    else if ( !m_bHeaderOn && m_bFooterOn )
2309
0
                                        nResId = RID_SCDLG_HFEDIT_FOOTER;
2310
0
                                    else if ( m_bHeaderOn && !m_bFooterOn )
2311
0
                                        nResId = RID_SCDLG_HFEDIT_HEADER;
2312
0
                                }
2313
0
                                else if ( bShareHeader && bShareFooter )
2314
0
                                {
2315
0
                                    if ( m_bHeaderOn && m_bFooterOn )
2316
0
                                        nResId = RID_SCDLG_HFEDIT;
2317
0
                                    else
2318
0
                                    {
2319
0
                                        if ( !m_bHeaderOn && m_bFooterOn )
2320
0
                                            nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
2321
0
                                        else if ( m_bHeaderOn && !m_bFooterOn )
2322
0
                                            nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
2323
0
                                    }
2324
0
                                }
2325
0
                                else if ( !bShareHeader &&  bShareFooter )
2326
0
                                {
2327
0
                                    if ( m_bHeaderOn && m_bFooterOn )
2328
0
                                        nResId = RID_SCDLG_HFEDIT_SFTR;
2329
0
                                    else if ( !m_bHeaderOn && m_bFooterOn )
2330
0
                                        nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
2331
0
                                    else if ( m_bHeaderOn && !m_bFooterOn )
2332
0
                                        nResId = RID_SCDLG_HFEDIT_HEADER;
2333
0
                                }
2334
0
                                else if (  bShareHeader && !bShareFooter )
2335
0
                                {
2336
0
                                    if ( m_bHeaderOn && m_bFooterOn )
2337
0
                                        nResId = RID_SCDLG_HFEDIT_SHDR;
2338
0
                                    else if ( !m_bHeaderOn && m_bFooterOn )
2339
0
                                        nResId = RID_SCDLG_HFEDIT_FOOTER;
2340
0
                                    else if ( m_bHeaderOn && !m_bFooterOn )
2341
0
                                        nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
2342
0
                                }
2343
0
                            }
2344
0
                        }
2345
2346
0
                        ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2347
2348
0
                        VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScHFEditDlg(
2349
0
                                                                                GetActiveDialogParent(),
2350
0
                                                                                rStyleSet,
2351
0
                                                                                aStr,
2352
0
                                                                                nResId));
2353
0
                        auto xRequest = std::make_shared<SfxRequest>(rReq);
2354
0
                        rReq.Ignore(); // the 'old' request is not relevant any more
2355
0
                        pDlg->StartExecuteAsync([this, pDlg, pStyleSheet, xRequest=std::move(xRequest)](sal_Int32 nResult){
2356
0
                            if ( nResult == RET_OK )
2357
0
                            {
2358
0
                                const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
2359
2360
0
                                if ( pOutSet )
2361
0
                                    m_pDocument->ModifyStyleSheet( *pStyleSheet, *pOutSet );
2362
2363
0
                                SetDocumentModified();
2364
0
                                xRequest->Done();
2365
0
                            }
2366
0
                            pDlg->disposeOnce();
2367
0
                        });
2368
0
                    }
2369
0
                }
2370
0
            }
2371
0
            break;
2372
2373
0
        default:
2374
0
        break;
2375
0
    }
2376
0
}
2377
2378
void ScDocShell::GetStatePageStyle( SfxItemSet&     rSet,
2379
                                    SCTAB           nCurTab )
2380
0
{
2381
0
    SfxWhichIter aIter(rSet);
2382
0
    sal_uInt16 nWhich = aIter.FirstWhich();
2383
0
    while ( nWhich )
2384
0
    {
2385
0
        switch (nWhich)
2386
0
        {
2387
0
            case SID_STATUS_PAGESTYLE:
2388
0
                rSet.Put( SfxStringItem( nWhich, m_pDocument->GetPageStyle( nCurTab ) ) );
2389
0
                break;
2390
2391
0
            case SID_HFEDIT:
2392
0
                {
2393
0
                    OUString            aStr        = m_pDocument->GetPageStyle( nCurTab );
2394
0
                    ScStyleSheetPool*   pStylePool  = m_pDocument->GetStyleSheetPool();
2395
0
                    SfxStyleSheetBase*  pStyleSheet = pStylePool->Find( aStr, SfxStyleFamily::Page );
2396
2397
0
                    OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
2398
2399
0
                    if ( pStyleSheet )
2400
0
                    {
2401
0
                        SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
2402
0
                        GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, m_bHeaderOn, m_bFooterOn );
2403
2404
0
                        if ( !m_bHeaderOn && !m_bFooterOn )
2405
0
                            rSet.DisableItem( nWhich );
2406
0
                    }
2407
0
                }
2408
0
                break;
2409
0
        }
2410
2411
0
        nWhich = aIter.NextWhich();
2412
0
    }
2413
0
}
2414
2415
void ScDocShell::GetState( SfxItemSet &rSet )
2416
0
{
2417
0
    bool bTabView = GetBestViewShell() != nullptr;
2418
2419
0
    SfxWhichIter aIter(rSet);
2420
0
    for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
2421
0
    {
2422
0
        if (!bTabView)
2423
0
        {
2424
0
            rSet.DisableItem(nWhich);
2425
0
            continue;
2426
0
        }
2427
2428
0
        switch (nWhich)
2429
0
        {
2430
0
            case FID_AUTO_CALC:
2431
0
                if ( m_pDocument->GetHardRecalcState() != ScDocument::HardRecalcState::OFF )
2432
0
                    rSet.DisableItem( nWhich );
2433
0
                else
2434
0
                    rSet.Put( SfxBoolItem( nWhich, m_pDocument->GetAutoCalc() ) );
2435
0
                break;
2436
2437
0
            case FID_CHG_RECORD:
2438
0
                if ( IsDocShared() )
2439
0
                    rSet.DisableItem( nWhich );
2440
0
                else
2441
0
                    rSet.Put( SfxBoolItem( nWhich,
2442
0
                        m_pDocument->GetChangeTrack() != nullptr ) );
2443
0
                break;
2444
2445
0
            case SID_CHG_PROTECT:
2446
0
                {
2447
0
                    ScChangeTrack* pChangeTrack = m_pDocument->GetChangeTrack();
2448
0
                    if ( pChangeTrack && !IsDocShared() )
2449
0
                        rSet.Put( SfxBoolItem( nWhich,
2450
0
                            pChangeTrack->IsProtected() ) );
2451
0
                    else
2452
0
                        rSet.DisableItem( nWhich );
2453
0
                }
2454
0
                break;
2455
2456
0
            case SID_DOCUMENT_COMPARE:
2457
0
                {
2458
0
                    if ( IsDocShared() )
2459
0
                    {
2460
0
                        rSet.DisableItem( nWhich );
2461
0
                    }
2462
0
                }
2463
0
                break;
2464
2465
            //  When a formula is edited, FID_RECALC must be enabled in any case. Recalc for
2466
            //  the doc was disabled once because of a bug if AutoCalc was on, but is now
2467
            //  always enabled because of another bug.
2468
2469
0
            case SID_TABLES_COUNT:
2470
0
                rSet.Put( SfxInt16Item( nWhich, m_pDocument->GetTableCount() ) );
2471
0
                break;
2472
2473
0
            case SID_TABLE_STYLES:
2474
0
                {
2475
0
                    ScTableStyles* pStyles = m_pDocument->GetTableStyles();
2476
0
                    if (pStyles)
2477
0
                    {
2478
0
                        tools::JsonWriter aTree;
2479
0
                        pStyles->generateJSON(aTree);
2480
0
                        OString aStr = aTree.finishAndGetAsOString();
2481
0
                        rSet.Put(
2482
0
                            SfxStringItem( nWhich, OStringToOUString( aStr, RTL_TEXTENCODING_UTF8 ) ) );
2483
0
                    }
2484
0
                }
2485
0
                break;
2486
2487
0
            case SID_ATTR_YEAR2000 :
2488
0
                rSet.Put( SfxUInt16Item( nWhich,
2489
0
                    m_pDocument->GetDocOptions().GetYear2000() ) );
2490
0
            break;
2491
2492
0
            case SID_SHARE_DOC:
2493
0
                {
2494
0
                    if ( IsReadOnly() || GetObjectShell()->isExportLocked() )
2495
0
                    {
2496
0
                        rSet.DisableItem( nWhich );
2497
0
                    }
2498
0
                }
2499
0
                break;
2500
0
            case SID_ATTR_PAGE_ORIENTATION:
2501
0
            case SID_SC_ATTR_PAGE_MARGIN:
2502
0
            case SID_SC_ATTR_PAGE_SIZE:
2503
0
                {
2504
0
                    ScViewData* pViewData = GetViewData();
2505
0
                    if (pViewData)
2506
0
                    {
2507
0
                        ScDocument& rDoc = GetDocument();
2508
0
                        const SCTAB nTab = pViewData->CurrentTabForData();
2509
0
                        OUString aStyleName = rDoc.GetPageStyle(nTab);
2510
0
                        ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
2511
0
                        if (pStylePool)
2512
0
                        {
2513
0
                            SfxStyleSheetBase* pStyleSheet
2514
0
                                = pStylePool->Find(aStyleName, SfxStyleFamily::Page);
2515
0
                            if (pStyleSheet)
2516
0
                            {
2517
0
                                const SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
2518
0
                                rSet.Put(rStyleSet.Get(ATTR_PAGE));
2519
0
                            }
2520
0
                        }
2521
0
                    }
2522
0
                }
2523
0
            break;
2524
0
            case SID_OPEN_HYPERLINK:
2525
0
                {
2526
0
                    ScViewData* pViewData = GetViewData();
2527
0
                    if (!pViewData)
2528
0
                    {
2529
0
                        rSet.DisableItem(nWhich);
2530
0
                        break;
2531
0
                    }
2532
2533
0
                    if (ScModule::get()->IsEditMode())
2534
0
                    {
2535
0
                        if (EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart()))
2536
0
                            if (!URLFieldHelper::IsCursorAtURLField(*pEditView, true))
2537
0
                                rSet.DisableItem(nWhich);
2538
0
                    }
2539
0
                    else
2540
0
                    {
2541
0
                        if (ScGridWindow* pWin = pViewData->GetActiveWin())
2542
0
                        {
2543
0
                            std::vector<UrlData> vUrls = pWin->GetEditUrls(pViewData->GetCurPos());
2544
0
                            if (vUrls.empty())
2545
0
                                rSet.DisableItem(nWhich);
2546
0
                        }
2547
0
                    }
2548
0
                }
2549
0
                break;
2550
2551
0
            case SID_ATTR_CHAR_FONTLIST:
2552
0
                rSet.Put( SvxFontListItem( m_pImpl->pFontList.get(), nWhich ) );
2553
0
                break;
2554
2555
0
            case SID_NOTEBOOKBAR:
2556
0
                {
2557
0
                    if (SfxBindings* pBindings = GetViewBindings())
2558
0
                    {
2559
0
                        bool bVisible = sfx2::SfxNotebookBar::StateMethod(*pBindings,
2560
0
                                                                          u"modules/scalc/ui/");
2561
0
                        rSet.Put( SfxBoolItem( SID_NOTEBOOKBAR, bVisible ) );
2562
0
                    }
2563
0
                }
2564
0
                break;
2565
2566
0
            case SID_LANGUAGE_STATUS:
2567
0
                {
2568
0
                    OUString sLanguage;
2569
0
                    sal_uInt16 nLangWhich = 0;
2570
0
                    LanguageType eLatin = LANGUAGE_DONTKNOW, eCjk = LANGUAGE_DONTKNOW,
2571
0
                        eCtl = LANGUAGE_DONTKNOW;
2572
2573
0
                    if (comphelper::LibreOfficeKit::isActive())
2574
0
                    {
2575
0
                        GetDocument().GetLanguage( eLatin, eCjk, eCtl );
2576
0
                        sLanguage = SvtLanguageTable::GetLanguageString(eLatin);
2577
2578
0
                        if (eLatin == LANGUAGE_NONE)
2579
0
                            sLanguage += ";-";
2580
0
                        else
2581
0
                            sLanguage += ";" + LanguageTag(eLatin).getBcp47(false);
2582
0
                    }
2583
0
                    else if (ScTabViewShell* pViewShell = GetBestViewShell())
2584
0
                    {
2585
0
                        ScMarkData aMark = pViewShell->GetViewData().GetMarkData();
2586
0
                        SCCOL  nCol = pViewShell->GetViewData().GetCurX();
2587
0
                        SCROW  nRow = pViewShell->GetViewData().GetCurY();
2588
0
                        SCTAB  nTab = pViewShell->GetViewData().CurrentTabForData();
2589
2590
0
                        aMark.SetMarkArea(ScRange(nCol, nRow, nTab));
2591
0
                        const ScPatternAttr* pSelAttrs = GetDocument().GetSelectionPattern(aMark);
2592
0
                        if (pSelAttrs)
2593
0
                        {
2594
0
                            const SfxItemSet& rItemSet = pSelAttrs->GetItemSet();
2595
0
                            nLangWhich = rItemSet.GetPool()->GetWhichIDFromSlotID(SID_ATTR_CHAR_LANGUAGE);
2596
0
                            if (SfxItemState::SET == rItemSet.GetItemState(nLangWhich))
2597
0
                                eLatin = static_cast<const SvxLanguageItem&>(rItemSet.Get(nLangWhich)).GetLanguage();
2598
2599
0
                            nLangWhich = rItemSet.GetPool()->GetWhichIDFromSlotID(SID_ATTR_CHAR_CJK_LANGUAGE);
2600
0
                            if (SfxItemState::SET == rItemSet.GetItemState(nLangWhich))
2601
0
                                eCjk = static_cast<const SvxLanguageItem&>(rItemSet.Get(nLangWhich)).GetLanguage();
2602
2603
0
                            nLangWhich = rItemSet.GetPool()->GetWhichIDFromSlotID(SID_ATTR_CHAR_CTL_LANGUAGE);
2604
0
                            if (SfxItemState::SET == rItemSet.GetItemState(nLangWhich))
2605
0
                                eCtl = static_cast<const SvxLanguageItem&>(rItemSet.Get(nLangWhich)).GetLanguage();
2606
2607
0
                            if (eLatin != LANGUAGE_DONTKNOW)
2608
0
                                sLanguage = SvtLanguageTable::GetLanguageString(eLatin);
2609
0
                            else if (eCjk != LANGUAGE_DONTKNOW)
2610
0
                                sLanguage = SvtLanguageTable::GetLanguageString(eCjk);
2611
0
                            else if (eCtl != LANGUAGE_DONTKNOW)
2612
0
                                sLanguage = SvtLanguageTable::GetLanguageString(eCtl);
2613
2614
0
                            if (sLanguage.isEmpty())
2615
0
                            {
2616
0
                                GetDocument().GetLanguage(eLatin, eCjk, eCtl);
2617
0
                                sLanguage = SvtLanguageTable::GetLanguageString(eLatin);
2618
0
                            }
2619
0
                        }
2620
0
                    }
2621
0
                    rSet.Put(SfxStringItem(nWhich, sLanguage));
2622
0
                }
2623
0
                break;
2624
0
                case SID_PROTECTPOS:
2625
0
                case SID_PROTECTSIZE:
2626
0
                {
2627
0
                    ScViewData* pViewData = GetViewData();
2628
0
                    if (pViewData)
2629
0
                    {
2630
0
                        const ScDrawView* pDrView = pViewData->GetScDrawView();
2631
0
                        const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
2632
0
                        if ( rMarkList.GetMarkCount() == 1 )
2633
0
                        {
2634
0
                            const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
2635
0
                            const SdrObjKind nSdrObjKind = pObj->GetObjIdentifier();
2636
2637
0
                            if ( nSdrObjKind == SdrObjKind::Graphic )
2638
0
                            {
2639
0
                                if (nWhich == SID_PROTECTSIZE)
2640
0
                                {
2641
0
                                    rSet.Put(SfxBoolItem(nWhich, pObj->IsResizeProtect()));
2642
0
                                    if (pObj->IsMoveProtect())
2643
0
                                        rSet.DisableItem( nWhich );
2644
0
                                }
2645
0
                                else
2646
0
                                    rSet.Put(SfxBoolItem(nWhich, pObj->IsMoveProtect()));
2647
2648
0
                                break;
2649
0
                            }
2650
0
                        }
2651
0
                    }
2652
0
                    rSet.DisableItem( nWhich );
2653
0
                }
2654
0
                break;
2655
0
            default:
2656
0
                {
2657
0
                }
2658
0
                break;
2659
0
        }
2660
0
    }
2661
0
}
2662
2663
void ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect, bool /*bOutputToWindow*/ )
2664
0
{
2665
2666
0
    SCTAB nVisTab = m_pDocument->GetVisibleTab();
2667
0
    if (!m_pDocument->HasTable(nVisTab))
2668
0
        return;
2669
2670
0
    vcl::text::ComplexTextLayoutFlags nOldLayoutMode = pDev->GetLayoutMode();
2671
0
    pDev->SetLayoutMode( vcl::text::ComplexTextLayoutFlags::Default );     // even if it's the same, to get the metafile action
2672
2673
0
    if ( nAspect == ASPECT_THUMBNAIL )
2674
0
    {
2675
0
        tools::Rectangle aBoundRect = GetVisArea( ASPECT_THUMBNAIL );
2676
0
        ScViewData aTmpData( *this, nullptr );
2677
0
        aTmpData.SetTabNo(nVisTab);
2678
0
        SnapVisArea( aBoundRect );
2679
0
        aTmpData.SetScreen( aBoundRect );
2680
0
        ScPrintFunc::DrawToDev( *m_pDocument, pDev, 1.0, aBoundRect, aTmpData, true );
2681
0
    }
2682
0
    else
2683
0
    {
2684
0
        tools::Rectangle aOldArea = SfxObjectShell::GetVisArea();
2685
0
        tools::Rectangle aNewArea = aOldArea;
2686
0
        ScViewData aTmpData( *this, nullptr );
2687
0
        aTmpData.SetTabNo(nVisTab);
2688
0
        SnapVisArea( aNewArea );
2689
0
        if ( aNewArea != aOldArea && (m_pDocument->GetPosLeft() > 0 || m_pDocument->GetPosTop() > 0) )
2690
0
            SfxObjectShell::SetVisArea( aNewArea );
2691
0
        aTmpData.SetScreen( aNewArea );
2692
0
        ScPrintFunc::DrawToDev( *m_pDocument, pDev, 1.0, aNewArea, aTmpData, true );
2693
0
    }
2694
2695
0
    pDev->SetLayoutMode( nOldLayoutMode );
2696
0
}
2697
2698
tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
2699
1.28k
{
2700
1.28k
    SfxObjectCreateMode eShellMode = GetCreateMode();
2701
1.28k
    if ( eShellMode == SfxObjectCreateMode::ORGANIZER )
2702
0
    {
2703
        //  without contents we also don't know how large are the contents;
2704
        //  return empty rectangle, it will then be calculated after the loading
2705
0
        return tools::Rectangle();
2706
0
    }
2707
2708
1.28k
    if( nAspect == ASPECT_THUMBNAIL )
2709
0
    {
2710
0
        SCTAB nVisTab = m_pDocument->GetVisibleTab();
2711
0
        if (!m_pDocument->HasTable(nVisTab))
2712
0
        {
2713
0
            nVisTab = 0;
2714
0
            const_cast<ScDocShell*>(this)->m_pDocument->SetVisibleTab(nVisTab);
2715
0
        }
2716
0
        Size aSize = m_pDocument->GetPageSize(nVisTab);
2717
0
        const tools::Long SC_PREVIEW_SIZE_X = 10000;
2718
0
        const tools::Long SC_PREVIEW_SIZE_Y = 12400;
2719
0
        tools::Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X, SC_PREVIEW_SIZE_Y);
2720
0
        if (aSize.Width() > aSize.Height())
2721
0
        {
2722
0
            aArea.SetRight( SC_PREVIEW_SIZE_Y );
2723
0
            aArea.SetBottom( SC_PREVIEW_SIZE_X );
2724
0
        }
2725
2726
0
        bool bNegativePage = m_pDocument->IsNegativePage( m_pDocument->GetVisibleTab() );
2727
0
        if ( bNegativePage )
2728
0
            ScDrawLayer::MirrorRectRTL( aArea );
2729
0
        SnapVisArea( aArea );
2730
0
        return aArea;
2731
0
    }
2732
1.28k
    else if( nAspect == ASPECT_CONTENT && eShellMode != SfxObjectCreateMode::EMBEDDED )
2733
0
    {
2734
        //  fetch visarea like after loading
2735
2736
0
        SCTAB nVisTab = m_pDocument->GetVisibleTab();
2737
0
        if (!m_pDocument->HasTable(nVisTab))
2738
0
        {
2739
0
            nVisTab = 0;
2740
0
            const_cast<ScDocShell*>(this)->m_pDocument->SetVisibleTab(nVisTab);
2741
0
        }
2742
0
        SCCOL nStartCol;
2743
0
        SCROW nStartRow;
2744
0
        m_pDocument->GetDataStart( nVisTab, nStartCol, nStartRow );
2745
0
        SCCOL nEndCol;
2746
0
        SCROW nEndRow;
2747
0
        m_pDocument->GetPrintArea( nVisTab, nEndCol, nEndRow );
2748
0
        if (nStartCol>nEndCol)
2749
0
            nStartCol = nEndCol;
2750
0
        if (nStartRow>nEndRow)
2751
0
            nStartRow = nEndRow;
2752
0
        tools::Rectangle aNewArea = m_pDocument
2753
0
                                ->GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
2754
0
        return aNewArea;
2755
0
    }
2756
1.28k
    else
2757
1.28k
        return SfxObjectShell::GetVisArea( nAspect );
2758
1.28k
}
2759
2760
namespace {
2761
2762
[[nodiscard]]
2763
tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCCOL& rStartCol )
2764
64.0k
{
2765
64.0k
    SCCOL nCol = 0;
2766
64.0k
    tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip);
2767
64.0k
    tools::Long nSnap = 0;
2768
22.1M
    while ( nCol<rDoc.MaxCol() )
2769
22.1M
    {
2770
22.1M
        tools::Long nAdd = rDoc.GetColWidth(nCol, nTab);
2771
22.1M
        if ( nSnap + nAdd/2 < nTwips || nCol < rStartCol )
2772
22.0M
        {
2773
22.0M
            nSnap += nAdd;
2774
22.0M
            ++nCol;
2775
22.0M
        }
2776
63.0k
        else
2777
63.0k
            break;
2778
22.1M
    }
2779
64.0k
    nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100);
2780
64.0k
    rStartCol = nCol;
2781
64.0k
    return nVal;
2782
64.0k
}
2783
2784
[[nodiscard]]
2785
tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCROW& rStartRow )
2786
64.0k
{
2787
64.0k
    SCROW nRow = 0;
2788
64.0k
    tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip);
2789
64.0k
    tools::Long nSnap = 0;
2790
2791
64.0k
    bool bFound = false;
2792
55.4M
    for (SCROW i = nRow; i <= rDoc.MaxRow(); ++i)
2793
55.4M
    {
2794
55.4M
        SCROW nLastRow;
2795
55.4M
        if (rDoc.RowHidden(i, nTab, nullptr, &nLastRow))
2796
315
        {
2797
315
            i = nLastRow;
2798
315
            continue;
2799
315
        }
2800
2801
55.4M
        nRow = i;
2802
55.4M
        tools::Long nAdd = rDoc.GetRowHeight(i, nTab);
2803
55.4M
        if ( nSnap + nAdd/2 < nTwips || nRow < rStartRow )
2804
55.4M
        {
2805
55.4M
            nSnap += nAdd;
2806
55.4M
            ++nRow;
2807
55.4M
        }
2808
63.9k
        else
2809
63.9k
        {
2810
63.9k
            bFound = true;
2811
63.9k
            break;
2812
63.9k
        }
2813
55.4M
    }
2814
64.0k
    if (!bFound)
2815
159
        nRow = rDoc.MaxRow();  // all hidden down to the bottom
2816
2817
64.0k
    nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100);
2818
64.0k
    rStartRow = nRow;
2819
64.0k
    return nVal;
2820
64.0k
}
2821
2822
}
2823
2824
void ScDocShell::SnapVisArea( tools::Rectangle& rRect ) const
2825
32.0k
{
2826
32.0k
    SCTAB nTab = m_pDocument->GetVisibleTab();
2827
32.0k
    tools::Long nOrigTop = rRect.Top();
2828
32.0k
    tools::Long nOrigLeft = rRect.Left();
2829
32.0k
    bool bNegativePage = m_pDocument->IsNegativePage( nTab );
2830
32.0k
    if ( bNegativePage )
2831
11
        ScDrawLayer::MirrorRectRTL( rRect );        // calculate with positive (LTR) values
2832
2833
32.0k
    SCCOL nCol = m_pDocument->GetPosLeft();
2834
32.0k
    tools::Long nSetLeft = SnapHorizontal( *m_pDocument, nTab, rRect.Left(), nCol );
2835
32.0k
    rRect.SetLeft( nSetLeft );
2836
32.0k
    ++nCol;                                         // at least one column
2837
32.0k
    tools::Long nCorrectionLeft = (nOrigLeft == 0 && nCol > 0) ? nSetLeft : 0; // initial correction
2838
32.0k
    rRect.SetRight( SnapHorizontal( *m_pDocument, nTab, rRect.Right() + nCorrectionLeft, nCol ));
2839
2840
32.0k
    SCROW nRow = m_pDocument->GetPosTop();
2841
32.0k
    tools::Long nSetTop = SnapVertical( *m_pDocument, nTab, rRect.Top(), nRow );
2842
32.0k
    rRect.SetTop( nSetTop );
2843
32.0k
    ++nRow;                                         // at least one row
2844
32.0k
    tools::Long nCorrectionTop = (nOrigTop == 0 && nRow > 0) ? nSetTop : 0; // initial correction
2845
32.0k
    rRect.SetBottom( SnapVertical( *m_pDocument, nTab, rRect.Bottom() + nCorrectionTop, nRow ));
2846
2847
32.0k
    if ( bNegativePage )
2848
11
        ScDrawLayer::MirrorRectRTL( rRect );        // back to real rectangle
2849
32.0k
}
2850
2851
void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
2852
                                            SCTAB             nCurTab,
2853
                                            bool&             rbHeader,
2854
                                            bool&             rbFooter )
2855
0
{
2856
0
    if ( !pStyleSet )
2857
0
    {
2858
0
        ScStyleSheetPool*  pStylePool  = m_pDocument->GetStyleSheetPool();
2859
0
        SfxStyleSheetBase* pStyleSheet = pStylePool->
2860
0
                                            Find( m_pDocument->GetPageStyle( nCurTab ),
2861
0
                                                  SfxStyleFamily::Page );
2862
2863
0
        OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" );
2864
2865
0
        if ( pStyleSheet )
2866
0
            pStyleSet = &pStyleSheet->GetItemSet();
2867
0
        else
2868
0
            rbHeader = rbFooter = false;
2869
0
    }
2870
2871
0
    OSL_ENSURE( pStyleSet, "PageStyle-Set not found! :-(" );
2872
0
    if (!pStyleSet)
2873
0
        return;
2874
2875
0
    const SvxSetItem*   pSetItem = nullptr;
2876
0
    const SfxItemSet*   pSet     = nullptr;
2877
2878
0
    pSetItem = &pStyleSet->Get( ATTR_PAGE_HEADERSET );
2879
0
    pSet     = &pSetItem->GetItemSet();
2880
0
    rbHeader = pSet->Get(ATTR_PAGE_ON).GetValue();
2881
2882
0
    pSetItem = &pStyleSet->Get( ATTR_PAGE_FOOTERSET );
2883
0
    pSet     = &pSetItem->GetItemSet();
2884
0
    rbFooter = pSet->Get(ATTR_PAGE_ON).GetValue();
2885
0
}
2886
2887
#if defined(_WIN32)
2888
bool ScDocShell::DdeGetData( const OUString& rItem,
2889
                             const OUString& rMimeType,
2890
                             css::uno::Any & rValue )
2891
{
2892
    SotClipboardFormatId eFormatId = SotExchange::GetFormatIdFromMimeType( rMimeType );
2893
    if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId)
2894
    {
2895
        if( rItem.equalsIgnoreAsciiCase( "Format" ) )
2896
        {
2897
            OString aFmtByte(OUStringToOString(m_aDdeTextFmt,
2898
                osl_getThreadTextEncoding()));
2899
            rValue <<= css::uno::Sequence< sal_Int8 >(
2900
                                        reinterpret_cast<const sal_Int8*>(aFmtByte.getStr()),
2901
                                        aFmtByte.getLength() + 1 );
2902
            return true;
2903
        }
2904
        ScImportExport aObj( *m_pDocument, rItem );
2905
        if ( !aObj.IsRef() )
2906
            return false;                           // invalid range
2907
2908
        if( m_aDdeTextFmt[0] == 'F' )
2909
            aObj.SetFormulas( true );
2910
        if( m_aDdeTextFmt == "SYLK" ||
2911
            m_aDdeTextFmt == "FSYLK" )
2912
        {
2913
            OString aData;
2914
            if( aObj.ExportByteString( aData, osl_getThreadTextEncoding(),
2915
                                        SotClipboardFormatId::SYLK ) )
2916
            {
2917
                rValue <<= css::uno::Sequence< sal_Int8 >(
2918
                                            reinterpret_cast<const sal_Int8*>(aData.getStr()),
2919
                                            aData.getLength() + 1 );
2920
                return true;
2921
            }
2922
            else
2923
                return false;
2924
        }
2925
        if( m_aDdeTextFmt == "CSV" ||
2926
            m_aDdeTextFmt == "FCSV" )
2927
            aObj.SetSeparator( ',' );
2928
        aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2929
        return aObj.ExportData( rMimeType, rValue );
2930
    }
2931
2932
    ScImportExport aObj( *m_pDocument, rItem );
2933
    aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2934
    return aObj.IsRef() && aObj.ExportData( rMimeType, rValue );
2935
}
2936
2937
bool ScDocShell::DdeSetData( const OUString& rItem,
2938
                             const OUString& rMimeType,
2939
                             const css::uno::Any & rValue )
2940
{
2941
    SotClipboardFormatId eFormatId = SotExchange::GetFormatIdFromMimeType( rMimeType );
2942
    if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId)
2943
    {
2944
        if( rItem.equalsIgnoreAsciiCase( "Format" ) )
2945
        {
2946
            if ( ScByteSequenceToString::GetString( m_aDdeTextFmt, rValue ) )
2947
            {
2948
                m_aDdeTextFmt = m_aDdeTextFmt.toAsciiUpperCase();
2949
                return true;
2950
            }
2951
            return false;
2952
        }
2953
        ScImportExport aObj( *m_pDocument, rItem );
2954
        if( m_aDdeTextFmt[0] == 'F' )
2955
            aObj.SetFormulas( true );
2956
        if( m_aDdeTextFmt == "SYLK" ||
2957
            m_aDdeTextFmt == "FSYLK" )
2958
        {
2959
            OUString aData;
2960
            if ( ScByteSequenceToString::GetString( aData, rValue ) )
2961
            {
2962
                return aObj.ImportString( aData, SotClipboardFormatId::SYLK );
2963
            }
2964
            return false;
2965
        }
2966
        if( m_aDdeTextFmt == "CSV" ||
2967
            m_aDdeTextFmt == "FCSV" )
2968
            aObj.SetSeparator( ',' );
2969
        OSL_ENSURE( false, "Implementation is missing" );
2970
        return false;
2971
    }
2972
    /*ScImportExport aObj( aDocument, rItem );
2973
    return aObj.IsRef() && ScImportExport::ImportData( rMimeType, rValue );*/
2974
    OSL_ENSURE( false, "Implementation is missing" );
2975
    return false;
2976
}
2977
#endif
2978
2979
::sfx2::SvLinkSource* ScDocShell::DdeCreateLinkSource( const OUString& rItem )
2980
0
{
2981
0
    if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get())
2982
0
        return nullptr;
2983
2984
    //  only check for valid item string - range is parsed again in ScServerObject ctor
2985
2986
    //  named range?
2987
0
    OUString aPos = rItem;
2988
0
    ScRangeName* pRange = m_pDocument->GetRangeName();
2989
0
    if( pRange )
2990
0
    {
2991
0
        const ScRangeData* pData = pRange->findByUpperName(ScGlobal::getCharClass().uppercase(aPos));
2992
0
        if (pData)
2993
0
        {
2994
0
            if( pData->HasType( ScRangeData::Type::RefArea    )
2995
0
                || pData->HasType( ScRangeData::Type::AbsArea )
2996
0
                || pData->HasType( ScRangeData::Type::AbsPos  ) )
2997
0
                aPos = pData->GetSymbol();           // continue with the name's contents
2998
0
        }
2999
0
    }
3000
3001
    // Address in DDE function must be always parsed as CONV_OOO so that it
3002
    // would always work regardless of current address conversion.  We do this
3003
    // because the address item in a DDE entry is *not* normalized when saved
3004
    // into ODF.
3005
0
    ScRange aRange;
3006
0
    bool bValid = ( (aRange.Parse(aPos, *m_pDocument, formula::FormulaGrammar::CONV_OOO ) & ScRefFlags::VALID) ||
3007
0
                    (aRange.aStart.Parse(aPos, *m_pDocument, formula::FormulaGrammar::CONV_OOO) & ScRefFlags::VALID) );
3008
3009
0
    ScServerObject* pObj = nullptr;            // NULL = error
3010
0
    if ( bValid )
3011
0
        pObj = new ScServerObject( this, rItem );
3012
3013
    //  GetLinkManager()->InsertServer() is in the ScServerObject ctor
3014
3015
0
    return pObj;
3016
0
}
3017
3018
void ScDocShell::LOKCommentNotify(LOKCommentNotificationType nType, const ScDocument& rDocument, const ScAddress& rPos, const ScPostIt* pNote)
3019
0
{
3020
0
    if ( !rDocument.IsDocVisible() || // don't want callbacks until document load
3021
0
         !comphelper::LibreOfficeKit::isActive() ||
3022
0
         comphelper::LibreOfficeKit::isTiledAnnotations() )
3023
0
        return;
3024
3025
0
    tools::JsonWriter aAnnotation;
3026
0
    {
3027
0
        auto commentNode = aAnnotation.startNode("comment");
3028
0
        aAnnotation.put("action", (nType == LOKCommentNotificationType::Add ? "Add" :
3029
0
                                   (nType == LOKCommentNotificationType::Remove ? "Remove" :
3030
0
                                    (nType == LOKCommentNotificationType::Modify ? "Modify" : "???"))));
3031
3032
0
        assert(pNote);
3033
0
        aAnnotation.put("id", pNote->GetId());
3034
0
        aAnnotation.put("tab", rPos.Tab());
3035
3036
0
        if (nType != LOKCommentNotificationType::Remove)
3037
0
        {
3038
0
            aAnnotation.put("author", pNote->GetAuthor());
3039
0
            aAnnotation.put("dateTime", pNote->GetDate());
3040
0
            if (const auto* pData = pNote->GetThreadedCommentData())
3041
0
            {
3042
0
                aAnnotation.put("text", pData->maRoot.maText);
3043
0
                aAnnotation.put("threaded", "true");
3044
0
                aAnnotation.put("resolved", pNote->IsResolved() ? "true" : "false");
3045
0
            }
3046
0
            else
3047
0
                aAnnotation.put("text", pNote->GetText());
3048
3049
            // Calculating the cell cursor position
3050
0
            ScViewData* pViewData = GetViewData();
3051
0
            if (pViewData && pViewData->GetActiveWin())
3052
0
                aAnnotation.put("cellRange", ScPostIt::NoteRangeToJsonString(rDocument, rPos));
3053
0
        }
3054
0
    }
3055
3056
0
    OString aPayload = aAnnotation.finishAndGetAsOString();
3057
3058
0
    ScViewData* pViewData = GetViewData();
3059
0
    SfxViewShell* pThisViewShell = ( pViewData ? pViewData->GetViewShell() : nullptr );
3060
0
    SfxViewShell* pViewShell = SfxViewShell::GetFirst();
3061
0
    while (pViewShell)
3062
0
    {
3063
0
        if (pThisViewShell == nullptr || pViewShell->GetDocId() == pThisViewShell->GetDocId())
3064
0
            pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
3065
0
        pViewShell = SfxViewShell::GetNext(*pViewShell);
3066
0
    }
3067
0
}
3068
3069
ScViewData* ScDocShell::GetViewData()
3070
4.97k
{
3071
4.97k
    SfxViewShell* pCur = SfxViewShell::Current();
3072
4.97k
    ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( pCur );
3073
4.97k
    return pViewSh ? &pViewSh->GetViewData() : nullptr;
3074
4.97k
}
3075
3076
SCTAB ScDocShell::GetCurTab()
3077
746
{
3078
    //! this must be made non-static and use a ViewShell from this document!
3079
3080
746
    ScViewData* pViewData = GetViewData();
3081
3082
746
    return pViewData ? pViewData->CurrentTabForData() : static_cast<SCTAB>(0);
3083
746
}
3084
3085
ScTabViewShell* ScDocShell::GetBestViewShell( bool bOnlyVisible )
3086
294k
{
3087
294k
    ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
3088
    // wrong Doc?
3089
294k
    if( pViewSh && pViewSh->GetViewData().GetDocShell() != this )
3090
0
        pViewSh = nullptr;
3091
294k
    if( !pViewSh )
3092
294k
    {
3093
        // 1. find ViewShell
3094
294k
        SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, bOnlyVisible );
3095
294k
        if( pFrame )
3096
0
        {
3097
0
            SfxViewShell* p = pFrame->GetViewShell();
3098
0
            pViewSh = dynamic_cast< ScTabViewShell *>( p );
3099
0
        }
3100
294k
    }
3101
294k
    return pViewSh;
3102
294k
}
3103
3104
SfxBindings* ScDocShell::GetViewBindings()
3105
273k
{
3106
    //  used to invalidate slots after changes to this document
3107
3108
273k
    SfxViewShell* pViewSh = GetBestViewShell();
3109
273k
    if (pViewSh)
3110
0
        return &pViewSh->GetViewFrame().GetBindings();
3111
273k
    else
3112
273k
        return nullptr;
3113
273k
}
3114
3115
ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo )      // static
3116
0
{
3117
0
    ScDocShell* pFound = nullptr;
3118
0
    SfxObjectShell* pShell = SfxObjectShell::GetFirst();
3119
0
    sal_uInt16 nShellCnt = 0;
3120
3121
0
    while ( pShell && !pFound )
3122
0
    {
3123
0
        if ( auto pDocSh = dynamic_cast<ScDocShell*>(pShell) )
3124
0
        {
3125
0
            if ( nShellCnt == nDocNo )
3126
0
                pFound = pDocSh;
3127
0
            else
3128
0
                ++nShellCnt;
3129
0
        }
3130
0
        pShell = SfxObjectShell::GetNext( *pShell );
3131
0
    }
3132
3133
0
    return pFound;
3134
0
}
3135
3136
IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void )
3137
0
{
3138
0
    assert( _pFileDlg && "ScDocShell::DialogClosedHdl(): no file dialog");
3139
0
    OSL_ENSURE( m_pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
3140
3141
0
    if ( ERRCODE_NONE == _pFileDlg->GetError() )
3142
0
    {
3143
0
        sal_uInt16 nSlot = m_pImpl->pRequest->GetSlot();
3144
0
        std::unique_ptr<SfxMedium> pMed = m_pImpl->pDocInserter->CreateMedium();
3145
        // #i87094# If a .odt was selected pMed is NULL.
3146
0
        if (pMed)
3147
0
        {
3148
0
            m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
3149
0
            if ( SID_DOCUMENT_COMPARE == nSlot )
3150
0
            {
3151
0
                if ( pMed->GetFilter() )
3152
0
                    m_pImpl->pRequest->AppendItem(
3153
0
                            SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
3154
0
                OUString sOptions = ScDocumentLoader::GetOptions( *pMed );
3155
0
                if ( !sOptions.isEmpty() )
3156
0
                    m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
3157
0
            }
3158
0
            const SfxPoolItem* pItem = nullptr;
3159
0
            const SfxInt16Item* pInt16Item(nullptr);
3160
0
            if (pMed->GetItemSet().GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET)
3161
0
            {
3162
0
                pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem);
3163
0
            }
3164
0
            if (pInt16Item)
3165
0
            {
3166
0
                m_pImpl->pRequest->AppendItem( *pItem );
3167
0
            }
3168
3169
0
            Execute( *(m_pImpl->pRequest) );
3170
0
        }
3171
0
    }
3172
3173
0
    m_pImpl->bIgnoreLostRedliningWarning = false;
3174
0
}
3175
3176
#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
3177
3178
void ScDocShell::EnableSharedSettings( bool bEnable )
3179
{
3180
    SetDocumentModified();
3181
3182
    if ( bEnable )
3183
    {
3184
        m_pDocument->EndChangeTracking();
3185
        m_pDocument->StartChangeTracking();
3186
3187
        // hide accept or reject changes dialog
3188
        sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
3189
        SfxViewFrame* pViewFrame = SfxViewFrame::Current();
3190
        if ( pViewFrame && pViewFrame->HasChildWindow( nId ) )
3191
        {
3192
            pViewFrame->ToggleChildWindow( nId );
3193
            SfxBindings* pBindings = GetViewBindings();
3194
            if ( pBindings )
3195
            {
3196
                pBindings->Invalidate( FID_CHG_ACCEPT );
3197
            }
3198
        }
3199
    }
3200
    else
3201
    {
3202
        m_pDocument->EndChangeTracking();
3203
    }
3204
3205
    ScChangeViewSettings aChangeViewSet;
3206
    aChangeViewSet.SetShowChanges( false );
3207
    m_pDocument->SetChangeViewSettings( aChangeViewSet );
3208
}
3209
3210
uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
3211
{
3212
    uno::Reference< frame::XModel > xModel;
3213
    ScModule* mod = ScModule::get();
3214
    try
3215
    {
3216
        mod->SetInSharedDocLoading(true);
3217
        uno::Reference< frame::XDesktop2 > xLoader = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
3218
        uno::Sequence aArgs{ comphelper::makePropertyValue(u"Hidden"_ustr, true) };
3219
3220
        if ( GetMedium() )
3221
        {
3222
            const SfxStringItem* pPasswordItem = GetMedium()->GetItemSet().GetItem(SID_PASSWORD, false);
3223
            if ( pPasswordItem && !pPasswordItem->GetValue().isEmpty() )
3224
            {
3225
                aArgs.realloc( 2 );
3226
                auto pArgs = aArgs.getArray();
3227
                pArgs[1].Name = "Password";
3228
                pArgs[1].Value <<= pPasswordItem->GetValue();
3229
            }
3230
            const SfxUnoAnyItem* pEncryptionItem = GetMedium()->GetItemSet().GetItem(SID_ENCRYPTIONDATA, false);
3231
            if (pEncryptionItem)
3232
            {
3233
                aArgs.realloc(aArgs.getLength() + 1);
3234
                auto pArgs = aArgs.getArray();
3235
                pArgs[aArgs.getLength() - 1].Name = "EncryptionData";
3236
                pArgs[aArgs.getLength() - 1].Value = pEncryptionItem->GetValue();
3237
            }
3238
        }
3239
3240
        xModel.set(
3241
            xLoader->loadComponentFromURL( GetSharedFileURL(), u"_blank"_ustr, 0, aArgs ),
3242
            uno::UNO_QUERY_THROW );
3243
        mod->SetInSharedDocLoading(false);
3244
    }
3245
    catch ( uno::Exception& )
3246
    {
3247
        OSL_FAIL( "ScDocShell::LoadSharedDocument(): caught exception" );
3248
        mod->SetInSharedDocLoading(false);
3249
        try
3250
        {
3251
            uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
3252
            xClose->close( true );
3253
            return uno::Reference< frame::XModel >();
3254
        }
3255
        catch ( uno::Exception& )
3256
        {
3257
            return uno::Reference< frame::XModel >();
3258
        }
3259
    }
3260
    return xModel;
3261
}
3262
3263
#endif
3264
3265
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */