Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/app/scmod.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 <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
21
#include <com/sun/star/ui/dialogs/XSLTFilterDialog.hpp>
22
#include <comphelper/lok.hxx>
23
#include <comphelper/processfactory.hxx>
24
#include <scitems.hxx>
25
#include <sfx2/app.hxx>
26
27
#include <editeng/flditem.hxx>
28
#include <editeng/outliner.hxx>
29
30
#include <sfx2/viewfrm.hxx>
31
#include <sfx2/objface.hxx>
32
#include <sfx2/toolbarids.hxx>
33
34
#include <IAnyRefDialog.hxx>
35
36
#include <svtools/ehdl.hxx>
37
#include <svtools/accessibilityoptions.hxx>
38
#include <svl/ctloptions.hxx>
39
#include <unotools/useroptions.hxx>
40
#include <sfx2/bindings.hxx>
41
#include <sfx2/request.hxx>
42
#include <sfx2/printer.hxx>
43
#include <editeng/langitem.hxx>
44
#include <svtools/colorcfg.hxx>
45
46
#include <svl/whiter.hxx>
47
#include <svx/dialogs.hrc>
48
#include <svl/inethist.hxx>
49
#include <vcl/svapp.hxx>
50
#include <vcl/weld/WaitObject.hxx>
51
#include <vcl/weld/Window.hxx>
52
#include <svx/svxerr.hxx>
53
#include <comphelper/diagnose_ex.hxx>
54
55
#include <editeng/unolingu.hxx>
56
#include <unotools/lingucfg.hxx>
57
#include <i18nlangtag/mslangid.hxx>
58
#include <i18nlangtag/languagetag.hxx>
59
#include <com/sun/star/i18n/ScriptType.hpp>
60
#include <com/sun/star/linguistic2/XThesaurus.hpp>
61
#include <ooo/vba/XSinkCaller.hpp>
62
63
#include <scmod.hxx>
64
#include <global.hxx>
65
#include <viewopti.hxx>
66
#include <docoptio.hxx>
67
#include <appoptio.hxx>
68
#include <defaultsoptions.hxx>
69
#include <formulaopt.hxx>
70
#include <inputopt.hxx>
71
#include <printopt.hxx>
72
#include <navicfg.hxx>
73
#include <addincfg.hxx>
74
#include <tabvwsh.hxx>
75
#include <prevwsh.hxx>
76
#include <docsh.hxx>
77
#include <drwlayer.hxx>
78
#include <uiitems.hxx>
79
#include <sc.hrc>
80
#include <scerrors.hrc>
81
#include <scstyles.hrc>
82
#include <globstr.hrc>
83
#include <scresid.hxx>
84
#include <bitmaps.hlst>
85
#include <inputhdl.hxx>
86
#include <inputwin.hxx>
87
#include <msgpool.hxx>
88
#include <detfunc.hxx>
89
#include <preview.hxx>
90
#include <dragdata.hxx>
91
#include <markdata.hxx>
92
#include <transobj.hxx>
93
#include <funcdesc.hxx>
94
95
#define ShellClass_ScModule
96
#include <scslots.hxx>
97
98
#include <scabstdlg.hxx>
99
#include <formula/errorcodes.hxx>
100
#include <documentlinkmgr.hxx>
101
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
102
#include <sfx2/lokhelper.hxx>
103
104
11
#define SC_IDLE_STEP     150
105
106
SFX_IMPL_INTERFACE(ScModule, SfxShell)
107
108
void ScModule::InitInterface_Impl()
109
11
{
110
11
    GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_APPLICATION,
111
11
                                            SfxVisibilityFlags::Standard | SfxVisibilityFlags::Client | SfxVisibilityFlags::Viewer,
112
11
                                            ToolbarId::Objectbar_App);
113
114
11
    GetStaticInterface()->RegisterStatusBar(StatusBarId::CalcStatusBar);
115
11
}
116
117
ScModule::ScModule( SfxObjectFactory* pFact ) :
118
11
    SfxModule("sc"_ostr, {pFact}),
119
11
    m_aIdleTimer("sc ScModule IdleTimer"),
120
11
    m_pDragData(new ScDragData),
121
11
    m_pSelTransfer( nullptr ),
122
11
    m_pRefInputHandler( nullptr ),
123
11
    m_nCurRefDlgId( 0 ),
124
11
    m_bIsWaterCan( false ),
125
11
    m_bIsInEditCommand( false ),
126
11
    m_bIsInExecuteDrop( false ),
127
11
    m_bIsInSharedDocLoading( false ),
128
11
    m_bIsInSharedDocSaving( false )
129
11
{
130
    // The ResManager (DLL data) is not yet initialized in the ctor!
131
11
    SetName(u"StarCalc"_ustr); // for Basic
132
133
11
    ResetDragObject();
134
135
    // InputHandler does not need to be created
136
137
    // Create ErrorHandler - was in Init()
138
    // Between OfficeApplication::Init and ScGlobal::Init
139
11
    SvxErrorHandler::ensure();
140
11
    m_pErrorHdl.reset( new SfxErrorHandler(RID_ERRHDLSC,
141
11
                                       ErrCodeArea::Sc,
142
11
                                       ErrCodeArea::Sc,
143
11
                                       GetResLocale()) );
144
145
11
    m_aIdleTimer.SetPriority(TaskPriority::DEFAULT_IDLE);
146
11
    m_aIdleTimer.SetTimeout(SC_IDLE_STEP);
147
11
    m_aIdleTimer.SetInvokeHandler( LINK( this, ScModule, IdleHandler ) );
148
11
    m_aIdleTimer.Start();
149
150
11
    m_pMessagePool = new ScMessagePool;
151
11
    SetPool( m_pMessagePool.get() );
152
153
11
    ScGlobal::InitTextHeight( *m_pMessagePool );
154
155
11
    StartListening( *SfxGetpApp() );       // for SfxHintId::Deinitializing
156
157
    // Initialize the color config
158
11
    GetColorConfig();
159
11
}
160
161
ScModule::~ScModule()
162
0
{
163
0
    assert( !m_pSelTransfer && "Selection Transfer object not deleted" );
164
165
    // Mostly here to prevent leaks during shutdown when running unit tests
166
    // Need to clear this early in the shutdown process, because it might hold references
167
    // to large complex things like ScDocument.
168
0
    try {
169
0
        css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard =
170
0
            css::datatransfer::clipboard::SystemClipboard::create(
171
0
                comphelper::getProcessComponentContext());
172
0
        xClipboard->setContents( nullptr, nullptr );
173
0
    } catch (css::uno::DeploymentException const&) {
174
        // ignore, sometimes happens that UNO is already shutdown by now
175
0
    }
176
177
    // InputHandler does not need to be deleted (there's none in the App anymore)
178
179
0
    m_pMessagePool.clear();
180
181
0
    m_pDragData.reset();
182
0
    m_pErrorHdl.reset();
183
184
0
    ScGlobal::Clear(); // Also calls ScDocumentPool::DeleteVersionMaps();
185
186
0
    ScInterpreterContextPool::ModuleExiting();
187
188
0
    DeleteCfg(); // Called from Exit()
189
0
}
190
191
void ScModule::ConfigurationChanged(utl::ConfigurationBroadcaster* p, ConfigurationHints eHints)
192
0
{
193
0
    if ( p == m_pColorConfig.get() )
194
0
    {
195
        // Test if detective objects have to be updated with new colors
196
        // (if the detective colors haven't been used yet, there's nothing to update)
197
0
        if ( ScDetectiveFunc::IsColorsInitialized() )
198
0
        {
199
0
            const svtools::ColorConfig& rColors = GetColorConfig();
200
0
            bool bArrows =
201
0
                ( ScDetectiveFunc::GetArrowColor() != rColors.GetColorValue(svtools::CALCDETECTIVE).nColor ||
202
0
                  ScDetectiveFunc::GetErrorColor() != rColors.GetColorValue(svtools::CALCDETECTIVEERROR).nColor );
203
0
            bool bComments =
204
0
                ( ScDetectiveFunc::GetCommentColor() != rColors.GetColorValue(svtools::CALCNOTESBACKGROUND).nColor );
205
0
            if ( bArrows || bComments )
206
0
            {
207
0
                ScDetectiveFunc::InitializeColors(); // get the new colors
208
209
                // update detective objects in all open documents
210
0
                SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
211
0
                while ( pObjSh )
212
0
                {
213
0
                    if ( auto pDocSh = dynamic_cast<ScDocShell * >(pObjSh) )
214
0
                    {
215
0
                        if ( bArrows )
216
0
                            ScDetectiveFunc( pDocSh->GetDocument(), 0 ).UpdateAllArrowColors();
217
0
                        if ( bComments )
218
0
                            ScDetectiveFunc::UpdateAllComments( pDocSh->GetDocument() );
219
0
                    }
220
0
                    pObjSh = SfxObjectShell::GetNext( *pObjSh );
221
0
                }
222
0
            }
223
0
        }
224
225
0
        const bool bKit = comphelper::LibreOfficeKit::isActive();
226
227
        //invalidate only the current view in tiled rendering mode, or all views otherwise
228
0
        SfxViewShell* pViewShell = bKit ? SfxViewShell::Current() : SfxViewShell::GetFirst();
229
0
        while (pViewShell)
230
0
        {
231
0
            if (ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(pViewShell))
232
0
            {
233
0
                ScViewRenderingOptions aViewRenderingOptions(pViewSh->GetViewRenderingData());
234
0
                Color aFillColor(m_pColorConfig->GetColorValue(svtools::DOCCOLOR).nColor);
235
0
                aViewRenderingOptions.SetDocColor(aFillColor);
236
0
                aViewRenderingOptions.SetColorSchemeName(svtools::ColorConfig::GetCurrentSchemeName());
237
0
                const bool bUnchanged(aViewRenderingOptions == pViewSh->GetViewRenderingData());
238
0
                if (!bUnchanged)
239
0
                    pViewSh->SetViewRenderingData(aViewRenderingOptions);
240
241
0
                if (SfxObjectShell* pKitCurrentObjSh = bKit ? SfxObjectShell::Current() : nullptr)
242
0
                {
243
0
                    ScModelObj* pScModelObj = comphelper::getFromUnoTunnel<ScModelObj>(pKitCurrentObjSh->GetModel());
244
0
                    SfxLokHelper::notifyViewRenderState(pViewSh, pScModelObj);
245
                    // In Online, the document color is the one used for the background, contrary to
246
                    // Writer and Draw that use the application background color.
247
0
                    pViewSh->libreOfficeKitViewCallback(LOK_CALLBACK_APPLICATION_BACKGROUND_COLOR,
248
0
                            aFillColor.AsRGBHexString().toUtf8());
249
0
                }
250
251
                // if nothing changed, and the hint was OnlyCurrentDocumentColorScheme we can skip invalidate
252
0
                const bool bSkipInvalidate = bKit ||(bUnchanged && eHints == ConfigurationHints::OnlyCurrentDocumentColorScheme);
253
0
                if (!bSkipInvalidate)
254
0
                {
255
0
                    pViewSh->PaintGrid();
256
0
                    pViewSh->PaintTop();
257
0
                    pViewSh->PaintLeft();
258
0
                    pViewSh->PaintExtras();
259
0
                }
260
261
0
                ScInputHandler* pHdl = pViewSh->GetInputHandler();
262
0
                if ( pHdl )
263
0
                    pHdl->ForgetLastPattern(); // EditEngine BackgroundColor may change
264
0
            }
265
0
            else if ( dynamic_cast<const ScPreviewShell*>( pViewShell) !=  nullptr )
266
0
            {
267
0
                vcl::Window* pWin = pViewShell->GetWindow();
268
0
                if (pWin)
269
0
                    pWin->Invalidate();
270
0
            }
271
0
            if (bKit)
272
0
                break;
273
0
            pViewShell = SfxViewShell::GetNext( *pViewShell );
274
0
        }
275
0
    }
276
0
    else if ( p == m_pCTLOptions.get() )
277
0
    {
278
        // for all documents: set digit language for printer, recalc output factor, update row heights
279
0
        SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
280
0
        while ( pObjSh )
281
0
        {
282
0
            if ( auto pDocSh = dynamic_cast<ScDocShell *>(pObjSh) )
283
0
            {
284
0
                OutputDevice* pPrinter = pDocSh->GetPrinter();
285
0
                if ( pPrinter )
286
0
                    pPrinter->SetDigitLanguage( GetOptDigitLanguage() );
287
288
0
                pDocSh->CalcOutputFactor();
289
290
0
                SCTAB nTabCount = pDocSh->GetDocument().GetTableCount();
291
0
                for (SCTAB nTab=0; nTab<nTabCount; nTab++)
292
0
                    pDocSh->AdjustRowHeight( 0, pDocSh->GetDocument().MaxRow(), nTab );
293
0
            }
294
0
            pObjSh = SfxObjectShell::GetNext( *pObjSh );
295
0
        }
296
297
        // for all views (table and preview): update digit language
298
0
        SfxViewShell* pSh = SfxViewShell::GetFirst();
299
0
        while ( pSh )
300
0
        {
301
0
            if (ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(pSh))
302
0
            {
303
                // set ref-device for EditEngine (re-evaluates digit settings)
304
0
                ScInputHandler* pHdl = GetInputHdl(pViewSh);
305
0
                if (pHdl)
306
0
                    pHdl->UpdateRefDevice();
307
308
0
                pViewSh->DigitLanguageChanged();
309
0
                pViewSh->PaintGrid();
310
0
            }
311
0
            else if (ScPreviewShell* pPreviewSh = dynamic_cast<ScPreviewShell*>(pSh))
312
0
            {
313
0
                ScPreview* pPreview = pPreviewSh->GetPreview();
314
315
0
                pPreview->GetOutDev()->SetDigitLanguage( GetOptDigitLanguage() );
316
0
                pPreview->Invalidate();
317
0
            }
318
319
0
            pSh = SfxViewShell::GetNext( *pSh );
320
0
        }
321
0
    }
322
0
}
323
324
void ScModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
325
54.4k
{
326
54.4k
    if ( rHint.GetId() == SfxHintId::Deinitializing )
327
0
    {
328
        // ConfigItems must be removed before ConfigManager
329
0
        DeleteCfg();
330
0
    }
331
54.4k
}
332
333
void ScModule::DeleteCfg()
334
0
{
335
0
    m_pViewCfg.reset(); // Saving happens automatically before Exit()
336
0
    m_pDocCfg.reset();
337
0
    m_pAppCfg.reset();
338
0
    m_pDefaultsCfg.reset();
339
0
    m_pFormulaCfg.reset();
340
0
    m_pInputCfg.reset();
341
0
    m_pPrintCfg.reset();
342
0
    m_pNavipiCfg.reset();
343
0
    m_pAddInCfg.reset();
344
345
0
    if ( m_pColorConfig )
346
0
    {
347
0
        m_pColorConfig->RemoveListener(this);
348
0
        m_pColorConfig.reset();
349
0
    }
350
0
    if ( m_pCTLOptions )
351
0
    {
352
0
        m_pCTLOptions->RemoveListener(this);
353
0
        m_pCTLOptions.reset();
354
0
    }
355
0
    m_pUserOptions.reset();
356
0
}
357
358
// Moved here from the App
359
360
void ScModule::Execute( SfxRequest& rReq )
361
0
{
362
0
    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
363
0
    SfxBindings* pBindings = pViewFrm ? &pViewFrm->GetBindings() : nullptr;
364
365
0
    const SfxItemSet*   pReqArgs    = rReq.GetArgs();
366
0
    sal_uInt16              nSlot       = rReq.GetSlot();
367
368
0
    switch ( nSlot )
369
0
    {
370
0
        case SID_CHOOSE_DESIGN:
371
0
            SfxApplication::CallAppBasic( u"Template.Samples.ShowStyles"_ustr );
372
0
            break;
373
0
        case SID_AUTOSPELL_CHECK:
374
0
            {
375
0
                bool bSet;
376
0
                const SfxPoolItem* pItem;
377
0
                if (pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ))
378
0
                    bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
379
0
                else if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) )
380
0
                    bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
381
0
                else
382
0
                {   // Toggle
383
0
                    ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
384
0
                    if (pViewSh)
385
0
                        bSet = !pViewSh->IsAutoSpell();
386
0
                    else
387
0
                        bSet = !ScModule::GetAutoSpellProperty();
388
0
                }
389
390
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK>( GetPool() ));
391
0
                aSet.Put( SfxBoolItem( SID_AUTOSPELL_CHECK, bSet ) );
392
0
                ModifyOptions( aSet );
393
0
                rReq.Done();
394
0
            }
395
0
            break;
396
397
0
        case SID_ATTR_METRIC:
398
0
            {
399
0
                const SfxPoolItem* pItem;
400
0
                if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) )
401
0
                {
402
0
                    FieldUnit eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
403
0
                    switch( eUnit )
404
0
                    {
405
0
                        case FieldUnit::MM:      // Just the units that are also in the dialog
406
0
                        case FieldUnit::CM:
407
0
                        case FieldUnit::INCH:
408
0
                        case FieldUnit::PICA:
409
0
                        case FieldUnit::POINT:
410
0
                            {
411
0
                                PutItem( *pItem );
412
0
                                ScAppOptions aNewOpts( GetAppOptions() );
413
0
                                aNewOpts.SetAppMetric( eUnit );
414
0
                                SetAppOptions( aNewOpts );
415
0
                                rReq.Done();
416
0
                            }
417
0
                            break;
418
0
                        default:
419
0
                        {
420
                            // added to avoid warnings
421
0
                        }
422
0
                    }
423
0
                }
424
0
            }
425
0
            break;
426
427
0
        case FID_AUTOCOMPLETE:
428
0
            {
429
0
                ScAppOptions aNewOpts( GetAppOptions() );
430
0
                bool bNew = !aNewOpts.GetAutoComplete();
431
0
                aNewOpts.SetAutoComplete( bNew );
432
0
                SetAppOptions( aNewOpts );
433
0
                if (pBindings)
434
0
                    pBindings->Invalidate( FID_AUTOCOMPLETE );
435
0
                rReq.Done();
436
0
            }
437
0
            break;
438
439
0
        case SID_DETECTIVE_AUTO:
440
0
            {
441
0
                ScAppOptions aNewOpts( GetAppOptions() );
442
0
                bool bNew = !aNewOpts.GetDetectiveAuto();
443
0
                const SfxBoolItem* pAuto = rReq.GetArg<SfxBoolItem>(SID_DETECTIVE_AUTO);
444
0
                if ( pAuto )
445
0
                    bNew = pAuto->GetValue();
446
447
0
                aNewOpts.SetDetectiveAuto( bNew );
448
0
                SetAppOptions( aNewOpts );
449
0
                if (pBindings)
450
0
                    pBindings->Invalidate( SID_DETECTIVE_AUTO );
451
0
                rReq.AppendItem( SfxBoolItem( SID_DETECTIVE_AUTO, bNew ) );
452
0
                rReq.Done();
453
0
            }
454
0
            break;
455
456
0
        case SID_PSZ_FUNCTION:
457
0
            if (pReqArgs)
458
0
            {
459
0
                const SfxUInt32Item & rItem = pReqArgs->Get(SID_PSZ_FUNCTION);
460
461
0
                ScAppOptions aNewOpts( GetAppOptions() );
462
0
                aNewOpts.SetStatusFunc( rItem.GetValue() );
463
0
                SetAppOptions( aNewOpts );
464
465
0
                if (pBindings)
466
0
                {
467
0
                    pBindings->Invalidate( SID_TABLE_CELL );
468
0
                    pBindings->Update( SID_TABLE_CELL ); // Immediately
469
470
0
                    pBindings->Invalidate( SID_PSZ_FUNCTION );
471
0
                    pBindings->Update( SID_PSZ_FUNCTION );
472
                    // If the menu is opened again immediately
473
0
                }
474
0
            }
475
0
            break;
476
477
0
        case SID_ATTR_LANGUAGE:
478
0
        case SID_ATTR_CHAR_CJK_LANGUAGE:
479
0
        case SID_ATTR_CHAR_CTL_LANGUAGE:
480
0
            {
481
0
                const SfxPoolItem* pItem;
482
0
                if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( GetPool().GetWhichIDFromSlotID(nSlot), true, &pItem ) )
483
0
                {
484
0
                    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>( SfxObjectShell::Current() );
485
0
                    if ( pDocSh )
486
0
                    {
487
0
                        ScDocument& rDoc = pDocSh->GetDocument();
488
0
                        LanguageType eNewLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
489
0
                        LanguageType eLatin, eCjk, eCtl;
490
0
                        rDoc.GetLanguage( eLatin, eCjk, eCtl );
491
0
                        LanguageType eOld = ( nSlot == SID_ATTR_CHAR_CJK_LANGUAGE ) ? eCjk :
492
0
                                            ( ( nSlot == SID_ATTR_CHAR_CTL_LANGUAGE ) ? eCtl : eLatin );
493
0
                        if ( eNewLang != eOld )
494
0
                        {
495
0
                            if ( nSlot == SID_ATTR_CHAR_CJK_LANGUAGE )
496
0
                                eCjk = eNewLang;
497
0
                            else if ( nSlot == SID_ATTR_CHAR_CTL_LANGUAGE )
498
0
                                eCtl = eNewLang;
499
0
                            else
500
0
                                eLatin = eNewLang;
501
502
0
                            rDoc.SetLanguage( eLatin, eCjk, eCtl );
503
504
0
                            ScInputHandler* pInputHandler = GetInputHdl();
505
0
                            if ( pInputHandler )
506
0
                                pInputHandler->UpdateSpellSettings(); // EditEngine flags
507
0
                            ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
508
0
                            if ( pViewSh )
509
0
                                pViewSh->UpdateDrawTextOutliner(); // EditEngine flags
510
511
0
                            pDocSh->SetDocumentModified();
512
0
                        }
513
0
                    }
514
0
                }
515
0
            }
516
0
            break;
517
518
0
        case FID_FOCUS_POSWND:
519
0
            {
520
0
                ScInputHandler* pHdl = GetInputHdl();
521
0
                if (pHdl)
522
0
                {
523
0
                    ScInputWindow* pWin = pHdl->GetInputWindow();
524
0
                    if (pWin)
525
0
                        pWin->PosGrabFocus();
526
0
                }
527
0
                rReq.Done();
528
0
            }
529
0
            break;
530
531
0
        case SID_OPEN_XML_FILTERSETTINGS:
532
0
        {
533
0
            try
534
0
            {
535
0
                css::uno::Reference < css::ui::dialogs::XExecutableDialog > xDialog = css::ui::dialogs::XSLTFilterDialog::create( ::comphelper::getProcessComponentContext());
536
0
                (void)xDialog->execute();
537
0
            }
538
0
            catch( css::uno::RuntimeException& )
539
0
            {
540
0
                DBG_UNHANDLED_EXCEPTION("sc.ui");
541
0
            }
542
0
        }
543
0
        break;
544
545
0
        default:
546
0
            OSL_FAIL( "ScApplication: Unknown Message." );
547
0
            break;
548
0
    }
549
0
}
550
551
void ScModule::GetState( SfxItemSet& rSet )
552
0
{
553
0
    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>( SfxObjectShell::Current() );
554
0
    ScTabViewShell* pTabViewShell = pDocSh ? pDocSh->GetBestViewShell() : nullptr;
555
556
0
    SfxWhichIter aIter(rSet);
557
0
    for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
558
0
    {
559
0
        if (!pTabViewShell)
560
0
        {
561
            // Not in the normal calc view shell (most likely in preview shell). Disable all actions.
562
0
            rSet.DisableItem(nWhich);
563
0
            continue;
564
0
        }
565
566
0
        switch ( nWhich )
567
0
        {
568
0
            case FID_AUTOCOMPLETE:
569
0
                rSet.Put( SfxBoolItem( nWhich, GetAppOptions().GetAutoComplete() ) );
570
0
                break;
571
0
            case SID_DETECTIVE_AUTO:
572
0
                rSet.Put( SfxBoolItem( nWhich, GetAppOptions().GetDetectiveAuto() ) );
573
0
                break;
574
0
            case SID_PSZ_FUNCTION:
575
0
                rSet.Put( SfxUInt32Item( nWhich, GetAppOptions().GetStatusFunc() ) );
576
0
                break;
577
0
            case SID_ATTR_METRIC:
578
0
                rSet.Put(SfxUInt16Item(nWhich, sal::static_int_cast<sal_uInt16>(GetMetric())));
579
0
                break;
580
0
            case SID_AUTOSPELL_CHECK:
581
0
                rSet.Put( SfxBoolItem( nWhich, pTabViewShell->IsAutoSpell()) );
582
0
                break;
583
0
            case SID_ATTR_LANGUAGE:
584
0
            case ATTR_CJK_FONT_LANGUAGE:        // WID for SID_ATTR_CHAR_CJK_LANGUAGE
585
0
            case ATTR_CTL_FONT_LANGUAGE:        // WID for SID_ATTR_CHAR_CTL_LANGUAGE
586
0
                {
587
0
                    LanguageType eLatin, eCjk, eCtl;
588
0
                    pDocSh->GetDocument().GetLanguage( eLatin, eCjk, eCtl );
589
0
                    LanguageType eLang = ( nWhich == ATTR_CJK_FONT_LANGUAGE ) ? eCjk :
590
0
                                        ( ( nWhich == ATTR_CTL_FONT_LANGUAGE ) ? eCtl : eLatin );
591
0
                    rSet.Put( SvxLanguageItem( eLang, nWhich ) );
592
0
                }
593
0
                break;
594
0
        }
595
0
    }
596
0
}
597
598
void ScModule::HideDisabledSlots( SfxItemSet& rSet )
599
0
{
600
0
    if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
601
0
    {
602
0
        SfxBindings& rBindings = pViewFrm->GetBindings();
603
0
        SfxWhichIter aIter( rSet );
604
0
        for( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich != 0; nWhich = aIter.NextWhich() )
605
0
        {
606
0
            ScViewUtil::HideDisabledSlot( rSet, rBindings, nWhich );
607
            // always disable the slots
608
0
            rSet.DisableItem( nWhich );
609
0
        }
610
0
    }
611
0
}
612
613
void ScModule::ResetDragObject()
614
11
{
615
11
    if (comphelper::LibreOfficeKit::isActive())
616
0
    {
617
0
        ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
618
0
        if (pViewShell)
619
0
            pViewShell->ResetDragObject();
620
0
    }
621
11
    else
622
11
    {
623
11
        m_pDragData->pCellTransfer = nullptr;
624
11
        m_pDragData->pDrawTransfer = nullptr;
625
11
        m_pDragData->pJumpLocalDoc = nullptr;
626
11
        m_pDragData->aLinkDoc.clear();
627
11
        m_pDragData->aLinkTable.clear();
628
11
        m_pDragData->aLinkArea.clear();
629
11
        m_pDragData->aJumpTarget.clear();
630
11
        m_pDragData->aJumpText.clear();
631
11
    }
632
11
}
633
634
const ScDragData* ScModule::GetDragData() const
635
0
{
636
0
    if (comphelper::LibreOfficeKit::isActive())
637
0
    {
638
0
        ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
639
0
        return pViewShell ? &pViewShell->GetDragData() : nullptr;
640
0
    }
641
642
0
    return m_pDragData.get();
643
0
}
644
645
void ScModule::SetDragObject( ScTransferObj* pCellObj, ScDrawTransferObj* pDrawObj )
646
0
{
647
0
    if (comphelper::LibreOfficeKit::isActive())
648
0
    {
649
0
        ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
650
0
        if (pViewShell)
651
0
            pViewShell->SetDragObject(pCellObj, pDrawObj);
652
0
    }
653
0
    else
654
0
    {
655
0
        ResetDragObject();
656
0
        m_pDragData->pCellTransfer = pCellObj;
657
0
        m_pDragData->pDrawTransfer = pDrawObj;
658
0
    }
659
0
}
660
661
void ScModule::SetDragLink(
662
    const OUString& rDoc, const OUString& rTab, const OUString& rArea )
663
0
{
664
0
    if (comphelper::LibreOfficeKit::isActive())
665
0
    {
666
0
        ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
667
0
        if (pViewShell)
668
0
            pViewShell->SetDragLink(rDoc, rTab, rArea);
669
0
    }
670
0
    else
671
0
    {
672
0
        ResetDragObject();
673
0
        m_pDragData->aLinkDoc   = rDoc;
674
0
        m_pDragData->aLinkTable = rTab;
675
0
        m_pDragData->aLinkArea  = rArea;
676
0
    }
677
0
}
678
679
void ScModule::SetDragJump(
680
    ScDocument* pLocalDoc, const OUString& rTarget, const OUString& rText )
681
0
{
682
0
    if (comphelper::LibreOfficeKit::isActive())
683
0
    {
684
0
        ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
685
0
        if (pViewShell)
686
0
            pViewShell->SetDragJump(pLocalDoc, rTarget, rText);
687
0
    }
688
0
    else
689
0
    {
690
0
        ResetDragObject();
691
692
0
        m_pDragData->pJumpLocalDoc = pLocalDoc;
693
0
        m_pDragData->aJumpTarget = rTarget;
694
0
        m_pDragData->aJumpText = rText;
695
0
    }
696
0
}
697
698
ScDocument* ScModule::GetClipDoc()
699
7.02M
{
700
    // called from document
701
7.02M
    SfxViewFrame* pViewFrame = nullptr;
702
7.02M
    ScTabViewShell* pViewShell = nullptr;
703
7.02M
    css::uno::Reference<css::datatransfer::XTransferable2> xTransferable;
704
705
7.02M
    if ((pViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current())))
706
0
        xTransferable.set(ScTabViewShell::GetClipData(pViewShell->GetViewData().GetActiveWin()));
707
7.02M
    else if ((pViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::GetFirst())))
708
0
        xTransferable.set(ScTabViewShell::GetClipData(pViewShell->GetViewData().GetActiveWin()));
709
7.02M
    else if ((pViewFrame = SfxViewFrame::GetFirst()))
710
0
    {
711
0
        css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard =
712
0
            pViewFrame->GetWindow().GetClipboard();
713
0
        xTransferable.set(xClipboard.is() ? xClipboard->getContents() : nullptr, css::uno::UNO_QUERY);
714
0
    }
715
716
7.02M
    const ScTransferObj* pObj = ScTransferObj::GetOwnClipboard(xTransferable);
717
7.02M
    if (pObj)
718
0
    {
719
0
        ScDocument* pDoc = pObj->GetDocument();
720
0
        assert((!pDoc || pDoc->IsClipboard()) && "Document is not clipboard, how can that be?");
721
0
        return pDoc;
722
0
    }
723
724
7.02M
    return nullptr;
725
7.02M
}
726
727
void ScModule::SetSelectionTransfer( ScSelectionTransferObj* pNew )
728
0
{
729
0
    m_pSelTransfer = pNew;
730
0
}
731
732
void ScModule::SetViewOptions( const ScViewOptions& rOpt )
733
0
{
734
0
    if ( !m_pViewCfg )
735
0
        m_pViewCfg.reset(new ScViewCfg);
736
737
0
    m_pViewCfg->SetOptions( rOpt );
738
0
}
739
740
const ScViewOptions& ScModule::GetViewOptions()
741
39.2k
{
742
39.2k
    if ( !m_pViewCfg )
743
5
        m_pViewCfg.reset( new ScViewCfg );
744
745
39.2k
    return *m_pViewCfg;
746
39.2k
}
747
748
void ScModule::SetDocOptions( const ScDocOptions& rOpt )
749
0
{
750
0
    if ( !m_pDocCfg )
751
0
        m_pDocCfg.reset( new ScDocCfg );
752
753
0
    m_pDocCfg->SetOptions( rOpt );
754
0
}
755
756
const ScDocOptions& ScModule::GetDocOptions()
757
39.2k
{
758
39.2k
    if ( !m_pDocCfg )
759
5
        m_pDocCfg.reset( new ScDocCfg );
760
761
39.2k
    return *m_pDocCfg;
762
39.2k
}
763
764
void ScModule::InsertEntryToLRUList(sal_uInt16 nFIndex)
765
0
{
766
0
    if(nFIndex == 0)
767
0
        return;
768
769
0
    const ScAppOptions& rAppOpt = GetAppOptions();
770
0
    sal_uInt16 nLRUFuncCount = std::min( rAppOpt.GetLRUFuncListCount(), sal_uInt16(LRU_MAX) );
771
0
    sal_uInt16* pLRUListIds = rAppOpt.GetLRUFuncList();
772
773
0
    sal_uInt16  aIdxList[LRU_MAX];
774
0
    sal_uInt16  n = 0;
775
0
    bool    bFound = false;
776
777
0
    while ((n < LRU_MAX) && n<nLRUFuncCount)                        // Iterate through old list
778
0
    {
779
0
        if (!bFound && (pLRUListIds[n]== nFIndex))
780
0
            bFound = true;                                          // First hit!
781
0
        else if (bFound)
782
0
            aIdxList[n  ] = pLRUListIds[n];                         // Copy after hit
783
0
        else if ((n+1) < LRU_MAX)
784
0
            aIdxList[n+1] = pLRUListIds[n];                         // Move before hit
785
0
        n++;
786
0
    }
787
0
    if (!bFound && (n < LRU_MAX))                                   // Entry not found?
788
0
        n++;                                                        // One more
789
0
    aIdxList[0] = nFIndex;                                          // Current on Top
790
791
0
    ScAppOptions aNewOpts(rAppOpt);                                 // Let App know
792
0
    aNewOpts.SetLRUFuncList(aIdxList, n);
793
0
    SetAppOptions(aNewOpts);
794
0
}
795
796
void ScModule::InsertOrEraseFavouritesListEntry(sal_uInt16 nFIndex, bool bInsert)
797
0
{
798
0
    const ScAppOptions& rAppOpt = GetAppOptions();
799
0
    std::unordered_set<sal_uInt16> sFavouriteFunctions = rAppOpt.GetFavouritesList();
800
801
0
    if (bInsert)
802
0
        sFavouriteFunctions.insert(nFIndex);
803
0
    else
804
0
        sFavouriteFunctions.erase(nFIndex);
805
806
0
    ScAppOptions aNewOpts(rAppOpt);
807
0
    aNewOpts.SetFavouritesList(sFavouriteFunctions);
808
0
    SetAppOptions(aNewOpts);
809
0
}
810
811
void ScModule::SetAppOptions( const ScAppOptions& rOpt )
812
0
{
813
0
    if ( !m_pAppCfg )
814
0
        m_pAppCfg.reset( new ScAppCfg );
815
816
0
    m_pAppCfg->SetOptions( rOpt );
817
0
}
818
819
void global_InitAppOptions()
820
9
{
821
9
    ScModule::get()->GetAppOptions();
822
9
}
823
824
const ScAppOptions& ScModule::GetAppOptions()
825
20
{
826
20
    if ( !m_pAppCfg )
827
11
        m_pAppCfg.reset( new ScAppCfg );
828
829
20
    return m_pAppCfg->GetOptions();
830
20
}
831
832
void ScModule::SetDefaultsOptions( const ScDefaultsOptions& rOpt )
833
0
{
834
0
    if ( !m_pDefaultsCfg )
835
0
        m_pDefaultsCfg.reset( new ScDefaultsCfg );
836
837
0
    m_pDefaultsCfg->SetOptions( rOpt );
838
0
}
839
840
const ScDefaultsOptions& ScModule::GetDefaultsOptions()
841
297k
{
842
297k
    if ( !m_pDefaultsCfg )
843
11
        m_pDefaultsCfg.reset( new ScDefaultsCfg );
844
845
297k
    return *m_pDefaultsCfg;
846
297k
}
847
848
void ScModule::SetFormulaOptions( const ScFormulaOptions& rOpt )
849
0
{
850
0
    if ( !m_pFormulaCfg )
851
0
        m_pFormulaCfg.reset( new ScFormulaCfg );
852
853
0
    m_pFormulaCfg->SetOptions( rOpt );
854
0
}
855
856
const ScFormulaOptions& ScModule::GetFormulaOptions()
857
78.4k
{
858
78.4k
    if ( !m_pFormulaCfg )
859
5
        m_pFormulaCfg.reset( new ScFormulaCfg );
860
861
78.4k
    return *m_pFormulaCfg;
862
78.4k
}
863
864
void ScModule::SetInputOptions( const ScInputOptions& rOpt )
865
0
{
866
0
    if ( !m_pInputCfg )
867
0
        m_pInputCfg.reset( new ScInputCfg );
868
869
0
    m_pInputCfg->SetOptions( rOpt );
870
0
}
871
872
const ScInputOptions& ScModule::GetInputOptions()
873
182k
{
874
182k
    if ( !m_pInputCfg )
875
7
        m_pInputCfg.reset( new ScInputCfg );
876
877
182k
    return m_pInputCfg->GetOptions();
878
182k
}
879
880
void ScModule::SetPrintOptions( const ScPrintOptions& rOpt )
881
0
{
882
0
    if ( !m_pPrintCfg )
883
0
        m_pPrintCfg.reset( new ScPrintCfg );
884
885
0
    m_pPrintCfg->SetOptions( rOpt );
886
0
}
887
888
const ScPrintOptions& ScModule::GetPrintOptions()
889
71.8k
{
890
71.8k
    if ( !m_pPrintCfg )
891
3
        m_pPrintCfg.reset( new ScPrintCfg );
892
893
71.8k
    return m_pPrintCfg->GetOptions();
894
71.8k
}
895
896
ScNavipiCfg& ScModule::GetNavipiCfg()
897
0
{
898
0
    if ( !m_pNavipiCfg )
899
0
        m_pNavipiCfg.reset( new ScNavipiCfg );
900
901
0
    return *m_pNavipiCfg;
902
0
}
903
904
ScAddInCfg& ScModule::GetAddInCfg()
905
8
{
906
8
    if ( !m_pAddInCfg )
907
8
        m_pAddInCfg.reset( new ScAddInCfg );
908
909
8
    return *m_pAddInCfg;
910
8
}
911
912
svtools::ColorConfig& ScModule::GetColorConfig()
913
1.30M
{
914
1.30M
    if ( !m_pColorConfig )
915
11
    {
916
11
        m_pColorConfig.reset( new svtools::ColorConfig );
917
11
        m_pColorConfig->AddListener(this);
918
11
    }
919
920
1.30M
    return *m_pColorConfig;
921
1.30M
}
922
923
bool ScModule::IsLOKViewInDarkMode()
924
0
{
925
0
    SfxViewShell* pKitSh = comphelper::LibreOfficeKit::isActive() ? SfxViewShell::Current() : nullptr;
926
0
    if( pKitSh )
927
0
    {
928
0
        Color aDocColor = pKitSh->GetColorConfigColor(svtools::DOCCOLOR);
929
0
        if( aDocColor.IsDark() )
930
0
            return true;
931
0
    }
932
0
    return false;
933
0
}
934
935
SvtUserOptions&  ScModule::GetUserOptions()
936
96
{
937
96
    if( !m_pUserOptions )
938
1
    {
939
1
        m_pUserOptions.reset( new SvtUserOptions );
940
1
    }
941
96
    return *m_pUserOptions;
942
96
}
943
944
FieldUnit ScModule::GetMetric()
945
0
{
946
0
    if (comphelper::LibreOfficeKit::isActive())
947
0
        return SfxModule::GetFieldUnit();
948
0
    return GetAppOptions().GetAppMetric();
949
0
}
950
951
LanguageType ScModule::GetOptDigitLanguage()
952
7.89k
{
953
7.89k
    SvtCTLOptions::TextNumerals eNumerals = SvtCTLOptions::GetCTLTextNumerals();
954
7.89k
    return ( eNumerals == SvtCTLOptions::NUMERALS_ARABIC ) ? LANGUAGE_ENGLISH_US :
955
7.89k
           ( eNumerals == SvtCTLOptions::NUMERALS_HINDI)   ? LANGUAGE_ARABIC_SAUDI_ARABIA :
956
0
                                                             LANGUAGE_SYSTEM;
957
7.89k
}
958
959
/**
960
 * Options
961
 *
962
 * Items from Calc options dialog and SID_AUTOSPELL_CHECK
963
 */
964
void ScModule::ModifyOptions( const SfxItemSet& rOptSet )
965
0
{
966
0
    bool bOldAutoSpell = GetAutoSpellProperty();
967
0
    LanguageType nOldSpellLang, nOldCjkLang, nOldCtlLang;
968
0
    GetSpellSettings( nOldSpellLang, nOldCjkLang, nOldCtlLang );
969
970
0
    if (!m_pAppCfg)
971
0
        GetAppOptions();
972
0
    OSL_ENSURE( m_pAppCfg, "AppOptions not initialised :-(" );
973
974
0
    if (!m_pInputCfg)
975
0
        GetInputOptions();
976
0
    OSL_ENSURE( m_pInputCfg, "InputOptions not initialised :-(" );
977
978
0
    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
979
0
    SfxBindings* pBindings = pViewFrm ? &pViewFrm->GetBindings() : nullptr;
980
981
0
    ScTabViewShell*         pViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
982
0
    ScDocShell*             pDocSh  = dynamic_cast<ScDocShell*>( SfxObjectShell::Current() );
983
0
    ScDocument*             pDoc    = pDocSh ? &pDocSh->GetDocument() : nullptr;
984
0
    bool bRepaint = false;
985
0
    bool bUpdateMarks = false;
986
0
    bool bUpdateRefDev = false;
987
0
    bool bCalcAll = false;
988
0
    bool bSaveAppOptions = false;
989
0
    bool bSaveInputOptions = false;
990
0
    bool bCompileErrorCells = false;
991
992
    //  SfxGetpApp()->SetOptions( rOptSet );
993
994
0
    ScAppOptions aAppOptions = m_pAppCfg->GetOptions();
995
996
    // No more linguistics
997
0
    if (const SfxUInt16Item* pItem = rOptSet.GetItemIfSet(SID_ATTR_METRIC))
998
0
    {
999
0
        PutItem( *pItem );
1000
0
        aAppOptions.SetAppMetric( static_cast<FieldUnit>(pItem->GetValue()) );
1001
0
        bSaveAppOptions = true;
1002
0
    }
1003
1004
0
    if (const ScUserListItem* pItem = rOptSet.GetItemIfSet(SCITEM_USERLIST))
1005
0
    {
1006
0
        ScGlobal::SetUserList( pItem->GetUserList() );
1007
0
        bSaveAppOptions = true;
1008
0
    }
1009
1010
0
    if (const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_OPT_SYNCZOOM))
1011
0
    {
1012
0
        aAppOptions.SetSynchronizeZoom( pItem->GetValue() );
1013
0
        bSaveAppOptions = true;
1014
0
    }
1015
1016
0
    if (const SfxUInt16Item* pItem = rOptSet.GetItemIfSet(SID_SC_OPT_KEY_BINDING_COMPAT))
1017
0
    {
1018
0
        sal_uInt16 nVal = pItem->GetValue();
1019
0
        ScOptionsUtil::KeyBindingType eOld = aAppOptions.GetKeyBindingType();
1020
0
        ScOptionsUtil::KeyBindingType eNew = static_cast<ScOptionsUtil::KeyBindingType>(nVal);
1021
0
        if (eOld != eNew)
1022
0
        {
1023
0
            aAppOptions.SetKeyBindingType(eNew);
1024
0
            bSaveAppOptions = true;
1025
0
            ScDocShell::ResetKeyBindings(eNew);
1026
0
        }
1027
0
    }
1028
1029
0
    if (const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_OPT_LINKS))
1030
0
    {
1031
0
        aAppOptions.SetLinksInsertedLikeMSExcel(pItem->GetValue());
1032
0
        bSaveAppOptions = true;
1033
0
    }
1034
1035
    // DefaultsOptions
1036
0
    if (const ScTpDefaultsItem* pItem = rOptSet.GetItemIfSet(SID_SCDEFAULTSOPTIONS))
1037
0
    {
1038
0
        const ScDefaultsOptions& rOpt = pItem->GetDefaultsOptions();
1039
0
        SetDefaultsOptions( rOpt );
1040
0
    }
1041
1042
    // FormulaOptions
1043
0
    if (const ScTpFormulaItem* pItem = rOptSet.GetItemIfSet(SID_SCFORMULAOPTIONS))
1044
0
    {
1045
0
        const ScFormulaOptions& rOpt = pItem->GetFormulaOptions();
1046
1047
0
        if (!m_pFormulaCfg || (*m_pFormulaCfg != rOpt))
1048
            // Formula options have changed. Repaint the column headers.
1049
0
            bRepaint = true;
1050
1051
0
        if (m_pFormulaCfg && m_pFormulaCfg->GetUseEnglishFuncName() != rOpt.GetUseEnglishFuncName())
1052
0
        {
1053
            // Re-compile formula cells with error as the error may have been
1054
            // caused by unresolved function names.
1055
0
            bCompileErrorCells = true;
1056
0
        }
1057
1058
        // Recalc for interpreter options changes.
1059
0
        if (m_pFormulaCfg && m_pFormulaCfg->GetCalcConfig() != rOpt.GetCalcConfig())
1060
0
            bCalcAll = true;
1061
1062
0
        if ( pDocSh )
1063
0
        {
1064
0
            pDocSh->SetFormulaOptions( rOpt );
1065
0
            pDocSh->SetDocumentModified();
1066
0
        }
1067
1068
        // ScDocShell::SetFormulaOptions() may check for changed settings, so
1069
        // set the new options here after that has been called.
1070
0
        if (!bCalcAll || rOpt.GetWriteCalcConfig())
1071
0
        {
1072
            // CalcConfig is new, didn't change or is global, simply set all.
1073
0
            SetFormulaOptions( rOpt );
1074
0
        }
1075
0
        else
1076
0
        {
1077
            // If "only for current document" was checked, reset those affected
1078
            // by that setting to previous values.
1079
0
            ScFormulaOptions aNewOpt( rOpt);
1080
0
            aNewOpt.GetCalcConfig().MergeDocumentSpecific( m_pFormulaCfg->GetCalcConfig());
1081
0
            SetFormulaOptions( aNewOpt);
1082
0
        }
1083
0
    }
1084
1085
    // ViewOptions
1086
0
    if (const ScTpViewItem* pItem = rOptSet.GetItemIfSet(SID_SCVIEWOPTIONS))
1087
0
    {
1088
0
        const ScViewOptions& rNewOpt = pItem->GetViewOptions();
1089
1090
0
        if ( pViewSh )
1091
0
        {
1092
0
            ScViewData&             rViewData = pViewSh->GetViewData();
1093
0
            const ScViewOptions&    rOldOpt   = rViewData.GetOptions();
1094
1095
0
            bool bAnchorList = rOldOpt.GetOption(sc::ViewOption::ANCHOR) !=
1096
0
                               rNewOpt.GetOption(sc::ViewOption::ANCHOR);
1097
1098
0
            if ( rOldOpt != rNewOpt )
1099
0
            {
1100
0
                rViewData.SetOptions( rNewOpt ); // Changes rOldOpt
1101
0
                rViewData.GetDocument().SetViewOptions( rNewOpt );
1102
0
                if (pDocSh)
1103
0
                    pDocSh->SetDocumentModified();
1104
0
                bRepaint = true;
1105
0
            }
1106
0
            if ( bAnchorList )
1107
0
                pViewSh->UpdateAnchorHandles();
1108
0
        }
1109
0
        SetViewOptions( rNewOpt );
1110
0
        if (pBindings)
1111
0
        {
1112
0
            pBindings->Invalidate(SID_HELPLINES_MOVE);
1113
0
        }
1114
0
    }
1115
1116
    // GridOptions
1117
    // Evaluate after ViewOptions, as GridOptions is a member of ViewOptions
1118
0
    if ( const SvxGridItem* pItem = rOptSet.GetItemIfSet(SID_ATTR_GRID_OPTIONS) )
1119
0
    {
1120
0
        ScGridOptions aNewGridOpt( *pItem );
1121
1122
0
        if ( pViewSh )
1123
0
        {
1124
0
            ScViewData&          rViewData = pViewSh->GetViewData();
1125
0
            ScViewOptions        aNewViewOpt( rViewData.GetOptions() );
1126
0
            const ScGridOptions& rOldGridOpt = aNewViewOpt.GetGridOptions();
1127
1128
0
            if ( rOldGridOpt != aNewGridOpt )
1129
0
            {
1130
0
                aNewViewOpt.SetGridOptions( aNewGridOpt );
1131
0
                rViewData.SetOptions( aNewViewOpt );
1132
0
                rViewData.GetDocument().SetViewOptions( aNewViewOpt );
1133
0
                if (pDocSh)
1134
0
                    pDocSh->SetDocumentModified();
1135
0
                bRepaint = true;
1136
0
            }
1137
0
        }
1138
0
        ScViewOptions aNewViewOpt ( GetViewOptions() );
1139
0
        aNewViewOpt.SetGridOptions( aNewGridOpt );
1140
0
        SetViewOptions( aNewViewOpt );
1141
0
        if (pBindings)
1142
0
        {
1143
0
            pBindings->Invalidate(SID_GRID_VISIBLE);
1144
0
            pBindings->Invalidate(SID_GRID_USE);
1145
0
        }
1146
0
    }
1147
1148
    // DocOptions
1149
0
    if ( const ScTpCalcItem* pItem = rOptSet.GetItemIfSet(SID_SCDOCOPTIONS) )
1150
0
    {
1151
0
        const ScDocOptions& rNewOpt = pItem->GetDocOptions();
1152
1153
0
        if ( pDoc )
1154
0
        {
1155
0
            const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1156
1157
0
            bRepaint = ( bRepaint || ( rOldOpt != rNewOpt )   );
1158
0
            bCalcAll =   bRepaint &&
1159
0
                         (  rOldOpt.IsIter()       != rNewOpt.IsIter()
1160
0
                         || rOldOpt.GetIterCount() != rNewOpt.GetIterCount()
1161
0
                         || rOldOpt.GetIterEps()   != rNewOpt.GetIterEps()
1162
0
                         || rOldOpt.IsIgnoreCase() != rNewOpt.IsIgnoreCase()
1163
0
                         || rOldOpt.IsCalcAsShown() != rNewOpt.IsCalcAsShown()
1164
0
                         || (rNewOpt.IsCalcAsShown() &&
1165
0
                            rOldOpt.GetStdPrecision() != rNewOpt.GetStdPrecision())
1166
0
                         || rOldOpt.IsMatchWholeCell() != rNewOpt.IsMatchWholeCell()
1167
0
                         || rOldOpt.GetYear2000()   != rNewOpt.GetYear2000()
1168
0
                         || rOldOpt.IsFormulaRegexEnabled() != rNewOpt.IsFormulaRegexEnabled()
1169
0
                         || rOldOpt.IsFormulaWildcardsEnabled() != rNewOpt.IsFormulaWildcardsEnabled()
1170
0
                         );
1171
0
            pDoc->SetDocOptions( rNewOpt );
1172
0
            pDocSh->SetDocumentModified();
1173
0
        }
1174
0
        SetDocOptions( rNewOpt );
1175
0
    }
1176
1177
    // Set TabDistance after the actual DocOptions
1178
0
    if ( const SfxUInt16Item* pItem = rOptSet.GetItemIfSet(SID_ATTR_DEFTABSTOP) )
1179
0
    {
1180
0
        sal_uInt16 nTabDist = pItem->GetValue();
1181
0
        ScDocOptions aOpt(GetDocOptions());
1182
0
        aOpt.SetTabDistance(nTabDist);
1183
0
        SetDocOptions( aOpt );
1184
1185
0
        if ( pDoc )
1186
0
        {
1187
0
            ScDocOptions aDocOpt(pDoc->GetDocOptions());
1188
0
            aDocOpt.SetTabDistance(nTabDist);
1189
0
            pDoc->SetDocOptions( aDocOpt );
1190
0
            pDocSh->SetDocumentModified();
1191
0
            if(pDoc->GetDrawLayer())
1192
0
                pDoc->GetDrawLayer()->SetDefaultTabulator(nTabDist);
1193
0
        }
1194
0
    }
1195
1196
    // AutoSpell after the DocOptions (due to being a member)
1197
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_AUTOSPELL_CHECK) ) // At DocOptions
1198
0
    {
1199
0
        bool bDoAutoSpell = pItem->GetValue();
1200
1201
0
        if (pViewSh)
1202
0
        {
1203
0
            if (pViewSh->IsAutoSpell() != bDoAutoSpell)
1204
0
            {
1205
0
                pViewSh->EnableAutoSpell(bDoAutoSpell);
1206
1207
0
                bRepaint = true;            // Because HideAutoSpell might be invalid
1208
                                            //TODO: Paint all Views?
1209
0
            }
1210
0
        }
1211
1212
0
        if ( bOldAutoSpell != bDoAutoSpell )
1213
0
            SetAutoSpellProperty( bDoAutoSpell );
1214
0
        if ( pDocSh )
1215
0
            pDocSh->PostPaintGridAll();                     // Due to marks
1216
0
        ScInputHandler* pInputHandler = GetInputHdl();
1217
0
        if ( pInputHandler )
1218
0
            pInputHandler->UpdateSpellSettings();           // EditEngine flags
1219
0
        if ( pViewSh )
1220
0
            pViewSh->UpdateDrawTextOutliner();              // EditEngine flags
1221
1222
0
        if (pBindings)
1223
0
            pBindings->Invalidate( SID_AUTOSPELL_CHECK );
1224
0
    }
1225
1226
    // InputOptions
1227
0
    ScInputOptions aInputOptions = m_pInputCfg->GetOptions();
1228
0
    if ( const SfxUInt16Item* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_SELECTIONPOS) )
1229
0
    {
1230
0
        aInputOptions.SetMoveDir( pItem->GetValue() );
1231
0
        bSaveInputOptions = true;
1232
0
    }
1233
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_SELECTION) )
1234
0
    {
1235
0
        aInputOptions.SetMoveSelection( pItem->GetValue() );
1236
0
        bSaveInputOptions = true;
1237
0
    }
1238
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_EDITMODE) )
1239
0
    {
1240
0
        aInputOptions.SetEnterEdit( pItem->GetValue() );
1241
0
        bSaveInputOptions = true;
1242
0
    }
1243
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_FMT_EXPAND) )
1244
0
    {
1245
0
        aInputOptions.SetExtendFormat( pItem->GetValue() );
1246
0
        bSaveInputOptions = true;
1247
0
    }
1248
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_RANGEFINDER) )
1249
0
    {
1250
0
        aInputOptions.SetRangeFinder( pItem->GetValue() );
1251
0
        bSaveInputOptions = true;
1252
0
    }
1253
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_REF_EXPAND) )
1254
0
    {
1255
0
        aInputOptions.SetExpandRefs( pItem->GetValue() );
1256
0
        bSaveInputOptions = true;
1257
0
    }
1258
0
    if (const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_OPT_SORT_REF_UPDATE))
1259
0
    {
1260
0
        aInputOptions.SetSortRefUpdate( pItem->GetValue());
1261
0
        bSaveInputOptions = true;
1262
0
    }
1263
1264
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_MARK_HEADER) )
1265
0
    {
1266
0
        aInputOptions.SetMarkHeader( pItem->GetValue() );
1267
0
        bSaveInputOptions = true;
1268
0
        bUpdateMarks = true;
1269
0
    }
1270
0
    if ( const SfxBoolItem* pItem = rOptSet.GetItemIfSet(SID_SC_INPUT_TEXTWYSIWYG) )
1271
0
    {
1272
0
        bool bNew = pItem->GetValue();
1273
0
        if ( bNew != aInputOptions.GetTextWysiwyg() )
1274
0
        {
1275
0
            aInputOptions.SetTextWysiwyg( bNew );
1276
0
            bSaveInputOptions = true;
1277
0
            bUpdateRefDev = true;
1278
0
        }
1279
0
    }
1280
0
    if( const SfxBoolItem* pItem = rOptSet.GetItemIfSet( SID_SC_INPUT_REPLCELLSWARN ) )
1281
0
    {
1282
0
        aInputOptions.SetReplaceCellsWarn( pItem->GetValue() );
1283
0
        bSaveInputOptions = true;
1284
0
    }
1285
1286
0
    if( const SfxBoolItem* pItem = rOptSet.GetItemIfSet( SID_SC_INPUT_LEGACY_CELL_SELECTION ) )
1287
0
    {
1288
0
        aInputOptions.SetLegacyCellSelection( pItem->GetValue() );
1289
0
        bSaveInputOptions = true;
1290
0
    }
1291
1292
0
    if( const SfxBoolItem* pItem = rOptSet.GetItemIfSet( SID_SC_INPUT_ENTER_PASTE_MODE ) )
1293
0
    {
1294
0
        aInputOptions.SetEnterPasteMode( pItem->GetValue() );
1295
0
        bSaveInputOptions = true;
1296
0
    }
1297
1298
0
    if( const SfxBoolItem* pItem = rOptSet.GetItemIfSet( SID_SC_INPUT_WARNACTIVESHEET ) )
1299
0
    {
1300
0
        aInputOptions.SetWarnActiveSheet( pItem->GetValue() );
1301
0
        bSaveInputOptions = true;
1302
0
    }
1303
1304
    // PrintOptions
1305
0
    if ( const ScTpPrintItem* pItem = rOptSet.GetItemIfSet(SID_SCPRINTOPTIONS) )
1306
0
    {
1307
0
        const ScPrintOptions& rNewOpt = pItem->GetPrintOptions();
1308
0
        SetPrintOptions( rNewOpt );
1309
1310
        // broadcast causes all previews to recalc page numbers
1311
0
        SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScPrintOptions ) );
1312
0
    }
1313
1314
0
    if ( bSaveAppOptions )
1315
0
        m_pAppCfg->SetOptions(aAppOptions);
1316
1317
0
    if ( bSaveInputOptions )
1318
0
        m_pInputCfg->SetOptions(aInputOptions);
1319
1320
    // Kick off recalculation?
1321
0
    if (pDoc && bCompileErrorCells)
1322
0
    {
1323
        // Re-compile cells with name error, and recalc if at least one cell
1324
        // has been re-compiled.  In the future we may want to find a way to
1325
        // recalc only those that are affected.
1326
0
        if (pDoc->CompileErrorCells(FormulaError::NoName))
1327
0
            bCalcAll = true;
1328
0
    }
1329
1330
0
    if ( pDoc && bCalcAll )
1331
0
    {
1332
0
        weld::WaitObject aWait( ScDocShell::GetActiveDialogParent() );
1333
0
        pDoc->CalcAll();
1334
0
        if ( pViewSh )
1335
0
            pViewSh->UpdateCharts( true );
1336
0
        else
1337
0
            ScDBFunc::DoUpdateCharts( ScAddress(), *pDoc, true );
1338
0
        if (pBindings)
1339
0
            pBindings->Invalidate( SID_ATTR_SIZE ); //SvxPosSize StatusControl Update
1340
0
    }
1341
1342
0
    if ( pViewSh && bUpdateMarks )
1343
0
        pViewSh->UpdateAutoFillMark();
1344
1345
    // Repaint View?
1346
0
    if ( pViewSh && bRepaint )
1347
0
    {
1348
0
        pViewSh->UpdateFixPos();
1349
0
        pViewSh->PaintGrid();
1350
0
        pViewSh->PaintTop();
1351
0
        pViewSh->PaintLeft();
1352
0
        pViewSh->PaintExtras();
1353
0
        pViewSh->InvalidateBorder();
1354
0
        if (pBindings)
1355
0
        {
1356
0
            pBindings->Invalidate( FID_TOGGLEHEADERS ); // -> Checks in menu
1357
0
            pBindings->Invalidate( FID_TOGGLESYNTAX );
1358
0
        }
1359
0
    }
1360
1361
    // update ref device (for all documents)
1362
0
    if ( !bUpdateRefDev )
1363
0
        return;
1364
1365
    // for all documents: recalc output factor, update row heights
1366
0
    SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
1367
0
    while ( pObjSh )
1368
0
    {
1369
0
        if ( auto pOneDocSh = dynamic_cast<ScDocShell *>(pObjSh) )
1370
0
        {
1371
0
            pOneDocSh->CalcOutputFactor();
1372
0
            SCTAB nTabCount = pOneDocSh->GetDocument().GetTableCount();
1373
0
            for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1374
0
                pOneDocSh->AdjustRowHeight( 0, pDocSh->GetDocument().MaxRow(), nTab );
1375
0
        }
1376
0
        pObjSh = SfxObjectShell::GetNext( *pObjSh );
1377
0
    }
1378
1379
    // for all (tab-) views:
1380
0
    SfxViewShell* pSh = SfxViewShell::GetFirst( true, checkSfxViewShell<ScTabViewShell> );
1381
0
    while ( pSh )
1382
0
    {
1383
0
        ScTabViewShell* pOneViewSh = static_cast<ScTabViewShell*>(pSh);
1384
1385
        // set ref-device for EditEngine
1386
0
        ScInputHandler* pHdl = GetInputHdl(pOneViewSh);
1387
0
        if (pHdl)
1388
0
            pHdl->UpdateRefDevice();
1389
1390
        // update view scale
1391
0
        ScViewData& rViewData = pOneViewSh->GetViewData();
1392
0
        pOneViewSh->SetZoom( rViewData.GetZoomX(), rViewData.GetZoomY(), false );
1393
1394
        // repaint
1395
0
        pOneViewSh->PaintGrid();
1396
0
        pOneViewSh->PaintTop();
1397
0
        pOneViewSh->PaintLeft();
1398
1399
0
        pSh = SfxViewShell::GetNext( *pSh, true, checkSfxViewShell<ScTabViewShell> );
1400
0
    }
1401
0
}
1402
1403
/**
1404
 * Input-Handler
1405
 */
1406
ScInputHandler* ScModule::GetInputHdl( ScTabViewShell* pViewSh, bool bUseRef )
1407
0
{
1408
0
    if ( !comphelper::LibreOfficeKit::isActive() && m_pRefInputHandler && bUseRef )
1409
0
        return m_pRefInputHandler;
1410
1411
0
    ScInputHandler* pHdl = nullptr;
1412
0
    if ( !pViewSh )
1413
0
    {
1414
        // in case a UIActive embedded object has no ViewShell (UNO component)
1415
        // the own calc view shell will be set as current, but no handling should happen
1416
0
        ScTabViewShell* pCurViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current()  );
1417
0
        if ( pCurViewSh && !pCurViewSh->GetUIActiveClient() )
1418
0
            pViewSh = pCurViewSh;
1419
0
    }
1420
1421
0
    if ( pViewSh )
1422
0
        pHdl = pViewSh->GetInputHandler(); // Viewshell always has one, from now on
1423
1424
    // If no ViewShell passed or active, we can get NULL
1425
0
    OSL_ENSURE( pHdl || !pViewSh, "GetInputHdl: no InputHandler found!" );
1426
0
    return pHdl;
1427
0
}
1428
1429
void ScModule::ViewShellChanged(bool bStopEditing /*=true*/)
1430
0
{
1431
0
    ScInputHandler* pHdl   = GetInputHdl();
1432
0
    ScTabViewShell* pShell = ScTabViewShell::GetActiveViewShell();
1433
0
    if ( pShell && pHdl )
1434
0
        pShell->UpdateInputHandler(false, bStopEditing);
1435
0
}
1436
1437
void ScModule::SetInputMode( ScInputMode eMode, const OUString* pInitText )
1438
0
{
1439
0
    ScInputHandler* pHdl = GetInputHdl();
1440
0
    if (pHdl)
1441
0
        pHdl->SetMode(eMode, pInitText);
1442
0
}
1443
1444
bool ScModule::IsEditMode()
1445
0
{
1446
0
    ScInputHandler* pHdl = GetInputHdl();
1447
0
    return pHdl && pHdl->IsEditMode();
1448
0
}
1449
1450
bool ScModule::IsInputMode()
1451
0
{
1452
0
    ScInputHandler* pHdl = GetInputHdl();
1453
0
    return pHdl && pHdl->IsInputMode();
1454
0
}
1455
1456
bool ScModule::InputKeyEvent( const KeyEvent& rKEvt, bool bStartEdit )
1457
0
{
1458
0
    ScInputHandler* pHdl = GetInputHdl();
1459
0
    return pHdl && pHdl->KeyInput( rKEvt, bStartEdit );
1460
0
}
1461
1462
void ScModule::InputEnterHandler( ScEnterMode nBlockMode, bool bBeforeSavingInLOK )
1463
0
{
1464
0
    if ( !SfxGetpApp()->IsDowning() ) // Not when quitting the program
1465
0
    {
1466
0
        ScInputHandler* pHdl = GetInputHdl();
1467
0
        if (pHdl)
1468
0
            pHdl->EnterHandler( nBlockMode, bBeforeSavingInLOK );
1469
0
    }
1470
0
}
1471
1472
void ScModule::InputCancelHandler()
1473
0
{
1474
0
    ScInputHandler* pHdl = GetInputHdl();
1475
0
    if (pHdl)
1476
0
        pHdl->CancelHandler();
1477
0
}
1478
1479
void ScModule::InputSelection( const EditView* pView )
1480
0
{
1481
0
    ScInputHandler* pHdl = GetInputHdl();
1482
0
    if (pHdl)
1483
0
        pHdl->InputSelection( pView );
1484
0
}
1485
1486
void ScModule::InputChanged( const EditView* pView )
1487
0
{
1488
0
    ScInputHandler* pHdl = GetInputHdl();
1489
0
    if (pHdl)
1490
0
        pHdl->InputChanged( pView, false );
1491
0
}
1492
1493
void ScModule::ViewShellGone( const ScTabViewShell* pViewSh )
1494
0
{
1495
0
    ScInputHandler* pHdl = GetInputHdl();
1496
0
    if (pHdl)
1497
0
        pHdl->ViewShellGone( pViewSh );
1498
0
}
1499
1500
void ScModule::SetRefInputHdl( ScInputHandler* pNew )
1501
0
{
1502
0
    m_pRefInputHandler = pNew;
1503
0
}
1504
1505
void ScModule::InputGetSelection( sal_Int32& rStart, sal_Int32& rEnd )
1506
0
{
1507
0
    ScInputHandler* pHdl = GetInputHdl();
1508
0
    if (pHdl)
1509
0
        pHdl->InputGetSelection( rStart, rEnd );
1510
0
}
1511
1512
void ScModule::InputSetSelection( sal_Int32 nStart, sal_Int32 nEnd )
1513
0
{
1514
0
    ScInputHandler* pHdl = GetInputHdl();
1515
0
    if (pHdl)
1516
0
        pHdl->InputSetSelection( nStart, nEnd );
1517
0
}
1518
1519
void ScModule::InputReplaceSelection( std::u16string_view aStr )
1520
0
{
1521
0
    ScInputHandler* pHdl = GetInputHdl();
1522
0
    if (pHdl)
1523
0
        pHdl->InputReplaceSelection( aStr );
1524
0
}
1525
1526
void ScModule::InputTurnOffWinEngine()
1527
0
{
1528
0
    ScInputHandler* pHdl = GetInputHdl();
1529
0
    if (pHdl)
1530
0
        pHdl->InputTurnOffWinEngine();
1531
0
}
1532
1533
void ScModule::ActivateInputWindow( const OUString* pStrFormula, bool bMatrix )
1534
0
{
1535
0
    ScInputHandler* pHdl = GetInputHdl();
1536
0
    if ( !pHdl )
1537
0
        return;
1538
1539
0
    ScInputWindow* pWin = pHdl->GetInputWindow();
1540
0
    if ( pStrFormula )
1541
0
    {
1542
        // Take over formula
1543
0
        if ( pWin )
1544
0
        {
1545
0
            pWin->SetFuncString( *pStrFormula, false );
1546
            // SetSumAssignMode due to sal_False not necessary
1547
0
        }
1548
0
        ScEnterMode nMode = bMatrix ? ScEnterMode::MATRIX : ScEnterMode::NORMAL;
1549
0
        pHdl->EnterHandler( nMode );
1550
1551
        // Without Invalidate the selection remains active, if the formula has not changed
1552
0
        if (pWin)
1553
0
            pWin->TextInvalidate();
1554
0
    }
1555
0
    else
1556
0
    {
1557
        // Cancel
1558
0
        if ( pWin )
1559
0
        {
1560
0
            pWin->SetFuncString( OUString(), false );
1561
            // SetSumAssignMode due to sal_False no necessary
1562
0
        }
1563
0
        pHdl->CancelHandler();
1564
0
    }
1565
0
}
1566
1567
/**
1568
 * Reference dialogs
1569
 */
1570
void ScModule::SetRefDialog( sal_uInt16 nId, bool bVis, SfxViewFrame* pViewFrm )
1571
0
{
1572
    //TODO: Move reference dialog handling to view
1573
    //      Just keep function autopilot here for references to other documents
1574
0
    if ( !(m_nCurRefDlgId == 0 || ( nId == m_nCurRefDlgId && !bVis )
1575
0
       || ( comphelper::LibreOfficeKit::isActive() )) )
1576
0
        return;
1577
1578
0
    if ( !pViewFrm )
1579
0
        pViewFrm = SfxViewFrame::Current();
1580
1581
    // bindings update causes problems with update of stylist if
1582
    // current style family has changed
1583
    //if ( pViewFrm )
1584
    //  pViewFrm->GetBindings().Update();       // to avoid trouble in LockDispatcher
1585
1586
    // before SetChildWindow
1587
0
    if ( comphelper::LibreOfficeKit::isActive() )
1588
0
    {
1589
0
        if ( bVis )
1590
0
            m_nCurRefDlgId = nId;
1591
0
    }
1592
0
    else
1593
0
    {
1594
0
        m_nCurRefDlgId = bVis ? nId : 0;
1595
0
    }
1596
1597
0
    if ( pViewFrm )
1598
0
    {
1599
        //  store the dialog id also in the view shell
1600
0
        SfxViewShell* pViewSh = pViewFrm->GetViewShell();
1601
0
        if (ScTabViewShell* pTabViewSh = dynamic_cast<ScTabViewShell*>(pViewSh))
1602
0
            pTabViewSh->SetCurRefDlgId(m_nCurRefDlgId);
1603
0
        else
1604
0
        {
1605
            // no ScTabViewShell - possible for example from a Basic macro
1606
0
            bVis = false;
1607
0
            m_nCurRefDlgId = 0;   // don't set nCurRefDlgId if no dialog is created
1608
0
        }
1609
1610
0
        pViewFrm->SetChildWindow( nId, bVis );
1611
0
    }
1612
1613
0
    SfxApplication* pSfxApp = SfxGetpApp();
1614
0
    pSfxApp->Broadcast( SfxHint( SfxHintId::ScRefModeChanged ) );
1615
0
}
1616
1617
static SfxChildWindow* lcl_GetChildWinFromCurrentView( sal_uInt16 nId )
1618
0
{
1619
0
    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1620
1621
    // #i46999# current view frame can be null (for example, when closing help)
1622
0
    return pViewFrm ? pViewFrm->GetChildWindow( nId ) : nullptr;
1623
0
}
1624
1625
static SfxChildWindow* lcl_GetChildWinFromAnyView( sal_uInt16 nId )
1626
0
{
1627
    // First, try the current view
1628
0
    SfxChildWindow* pChildWnd = lcl_GetChildWinFromCurrentView( nId );
1629
0
    if ( pChildWnd )
1630
0
        return pChildWnd;           // found in the current view
1631
1632
    //  if not found there, get the child window from any open view
1633
    //  it can be open only in one view because nCurRefDlgId is global
1634
1635
0
    SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst();
1636
0
    while ( pViewFrm )
1637
0
    {
1638
0
        pChildWnd = pViewFrm->GetChildWindow( nId );
1639
0
        if ( pChildWnd )
1640
0
            return pChildWnd;       // found in any view
1641
1642
0
        pViewFrm = SfxViewFrame::GetNext( *pViewFrm );
1643
0
    }
1644
1645
0
    return nullptr;                    // none found
1646
0
}
1647
1648
bool ScModule::IsModalMode(SfxObjectShell* pDocSh)
1649
0
{
1650
    //TODO: Move reference dialog handling to view
1651
    //      Just keep function autopilot here for references to other documents
1652
0
    bool bIsModal = false;
1653
1654
0
    if ( m_nCurRefDlgId )
1655
0
    {
1656
0
        SfxChildWindow* pChildWnd = lcl_GetChildWinFromCurrentView( m_nCurRefDlgId );
1657
0
        if ( pChildWnd )
1658
0
        {
1659
0
            if (pChildWnd->GetController())
1660
0
            {
1661
0
                IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetController().get());
1662
0
                assert(pRefDlg);
1663
0
                bIsModal = pChildWnd->IsVisible() && pRefDlg &&
1664
0
                    !( pRefDlg->IsRefInputMode() && pRefDlg->IsDocAllowed(pDocSh) );
1665
0
            }
1666
0
        }
1667
0
        else if ( pDocSh && comphelper::LibreOfficeKit::isActive() )
1668
0
        {
1669
            // m_nCurRefDlgId is not deglobalized so it can be set by other view
1670
            // in LOK case when no ChildWindow for this view was detected -> fallback
1671
0
            ScInputHandler* pHdl = GetInputHdl();
1672
0
            if ( pHdl )
1673
0
                bIsModal = pHdl->IsModalMode(*pDocSh);
1674
0
        }
1675
0
    }
1676
0
    else if (pDocSh)
1677
0
    {
1678
0
        ScInputHandler* pHdl = GetInputHdl();
1679
0
        if ( pHdl )
1680
0
            bIsModal = pHdl->IsModalMode(*pDocSh);
1681
0
    }
1682
1683
0
    return bIsModal;
1684
0
}
1685
1686
bool ScModule::IsTableLocked()
1687
0
{
1688
    //TODO: Move reference dialog handling to view
1689
    //      Just keep function autopilot here for references to other documents
1690
0
    bool bLocked = false;
1691
1692
    // Up until now just for ScAnyRefDlg
1693
0
    if ( m_nCurRefDlgId )
1694
0
    {
1695
0
        SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( m_nCurRefDlgId );
1696
0
        if ( pChildWnd )
1697
0
        {
1698
0
            if (pChildWnd->GetController())
1699
0
            {
1700
0
                IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetController().get());
1701
0
                assert(pRefDlg);
1702
0
                if (pRefDlg)
1703
0
                    bLocked = pRefDlg->IsTableLocked();
1704
0
            }
1705
0
        }
1706
0
        else if (!comphelper::LibreOfficeKit::isActive())
1707
0
            bLocked = true;     // for other views, see IsModalMode
1708
0
    }
1709
1710
    // We can't stop LOK clients from switching part, and getting out of sync.
1711
0
    assert(!bLocked || !comphelper::LibreOfficeKit::isActive());
1712
1713
0
    return bLocked;
1714
0
}
1715
1716
bool ScModule::IsRefDialogOpen()
1717
0
{
1718
    //TODO: Move reference dialog handling to view
1719
    //      Just keep function autopilot here for references to other documents
1720
0
    bool bIsOpen = false;
1721
1722
0
    if ( m_nCurRefDlgId )
1723
0
    {
1724
0
        SfxChildWindow* pChildWnd = lcl_GetChildWinFromCurrentView( m_nCurRefDlgId );
1725
0
        if ( pChildWnd )
1726
0
            bIsOpen = pChildWnd->IsVisible();
1727
0
    }
1728
1729
0
    return bIsOpen;
1730
0
}
1731
1732
bool ScModule::IsFormulaMode()
1733
0
{
1734
    //TODO: Move reference dialog handling to view
1735
    //      Just keep function autopilot here for references to other documents
1736
0
    bool bIsFormula = false;
1737
1738
0
    if ( m_nCurRefDlgId )
1739
0
    {
1740
0
        SfxChildWindow* pChildWnd = nullptr;
1741
1742
0
        if ( comphelper::LibreOfficeKit::isActive() )
1743
0
            pChildWnd = lcl_GetChildWinFromCurrentView( m_nCurRefDlgId );
1744
0
        else
1745
0
            pChildWnd = lcl_GetChildWinFromAnyView( m_nCurRefDlgId );
1746
1747
0
        if ( pChildWnd )
1748
0
        {
1749
0
            if (pChildWnd->GetController())
1750
0
            {
1751
0
                IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetController().get());
1752
0
                assert(pRefDlg);
1753
0
                bIsFormula = pChildWnd->IsVisible() && pRefDlg && pRefDlg->IsRefInputMode();
1754
0
            }
1755
0
        }
1756
0
        else if ( comphelper::LibreOfficeKit::isActive() )
1757
0
        {
1758
            // m_nCurRefDlgId is not deglobalized so it can be set by other view
1759
            // in LOK case when no ChildWindow for this view was detected -> fallback
1760
0
            ScInputHandler* pHdl = GetInputHdl();
1761
0
            if ( pHdl )
1762
0
                bIsFormula = pHdl->IsFormulaMode();
1763
0
        }
1764
0
    }
1765
0
    else
1766
0
    {
1767
0
        ScInputHandler* pHdl = GetInputHdl();
1768
0
        if ( pHdl )
1769
0
            bIsFormula = pHdl->IsFormulaMode();
1770
0
    }
1771
1772
0
    if (m_bIsInEditCommand)
1773
0
        bIsFormula = true;
1774
1775
0
    return bIsFormula;
1776
0
}
1777
1778
static void lcl_MarkedTabs( const ScMarkData& rMark, SCTAB& rStartTab, SCTAB& rEndTab )
1779
0
{
1780
0
    if (rMark.GetSelectCount() > 1)
1781
0
    {
1782
0
        rEndTab = rMark.GetLastSelected();
1783
0
        rStartTab = rMark.GetFirstSelected();
1784
0
    }
1785
0
}
1786
1787
void ScModule::SetReference( const ScRange& rRef, ScDocument& rDoc,
1788
                                    const ScMarkData* pMarkData )
1789
0
{
1790
    //TODO: Move reference dialog handling to view
1791
    //      Just keep function autopilot here for references to other documents
1792
1793
    // In RefDialogs we also trigger the ZoomIn, if the Ref's Start and End are different
1794
0
    ScRange aNew = rRef;
1795
0
    aNew.PutInOrder(); // Always in the right direction
1796
1797
0
    if( m_nCurRefDlgId )
1798
0
    {
1799
0
        SfxChildWindow* pChildWnd = nullptr;
1800
1801
0
        if ( comphelper::LibreOfficeKit::isActive() )
1802
0
            pChildWnd = lcl_GetChildWinFromCurrentView( m_nCurRefDlgId );
1803
0
        else
1804
0
            pChildWnd = lcl_GetChildWinFromAnyView( m_nCurRefDlgId );
1805
1806
0
        OSL_ENSURE( pChildWnd, "NoChildWin" );
1807
0
        if ( pChildWnd )
1808
0
        {
1809
0
            if ( m_nCurRefDlgId == SID_OPENDLG_CONSOLIDATE && pMarkData )
1810
0
            {
1811
0
                SCTAB nStartTab = aNew.aStart.Tab();
1812
0
                SCTAB nEndTab   = aNew.aEnd.Tab();
1813
0
                lcl_MarkedTabs( *pMarkData, nStartTab, nEndTab );
1814
0
                aNew.aStart.SetTab(nStartTab);
1815
0
                aNew.aEnd.SetTab(nEndTab);
1816
0
            }
1817
1818
0
            if (pChildWnd->GetController())
1819
0
            {
1820
0
                IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetController().get());
1821
0
                assert(pRefDlg);
1822
0
                if(pRefDlg)
1823
0
                {
1824
                    // hide the (color) selection now instead of later from LoseFocus,
1825
                    // don't abort the ref input that causes this call (bDoneRefMode = sal_False)
1826
0
                    pRefDlg->HideReference( false );
1827
0
                    pRefDlg->SetReference( aNew, rDoc );
1828
0
                }
1829
0
            }
1830
0
        }
1831
0
        else if ( comphelper::LibreOfficeKit::isActive() )
1832
0
        {
1833
            // m_nCurRefDlgId is not deglobalized so it can be set by other view
1834
            // in LOK case when no ChildWindow for this view was detected -> fallback
1835
0
            ScInputHandler* pHdl = GetInputHdl();
1836
0
            if (pHdl)
1837
0
                pHdl->SetReference( aNew, rDoc );
1838
0
        }
1839
0
    }
1840
0
    else
1841
0
    {
1842
0
        ScInputHandler* pHdl = GetInputHdl();
1843
0
        if (pHdl)
1844
0
            pHdl->SetReference( aNew, rDoc );
1845
0
        else
1846
0
        {
1847
0
            OSL_FAIL("SetReference without receiver");
1848
0
        }
1849
0
    }
1850
0
}
1851
1852
/**
1853
 * Multiple selection
1854
 */
1855
void ScModule::AddRefEntry()
1856
0
{
1857
    //TODO: Move reference dialog handling to view
1858
    //      Just keep function autopilot here for references to other documents
1859
0
    if ( m_nCurRefDlgId )
1860
0
    {
1861
0
        SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( m_nCurRefDlgId );
1862
0
        OSL_ENSURE( pChildWnd, "NoChildWin" );
1863
0
        if ( pChildWnd )
1864
0
        {
1865
0
            if (pChildWnd->GetController())
1866
0
            {
1867
0
                IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetController().get());
1868
0
                assert(pRefDlg);
1869
0
                if (pRefDlg)
1870
0
                {
1871
0
                    pRefDlg->AddRefEntry();
1872
0
                }
1873
0
            }
1874
0
        }
1875
0
    }
1876
0
    else
1877
0
    {
1878
0
        ScInputHandler* pHdl = GetInputHdl();
1879
0
        if (pHdl)
1880
0
            pHdl->AddRefEntry();
1881
0
    }
1882
0
}
1883
1884
void ScModule::EndReference()
1885
0
{
1886
    //TODO: Move reference dialog handling to view
1887
    //      Just keep function autopilot here for references to other documents
1888
1889
    // We also annul the ZoomIn again in RefDialogs
1890
1891
    //FIXME: ShowRefFrame at InputHdl, if the Function AutoPilot is open?
1892
0
    if ( !m_nCurRefDlgId )
1893
0
        return;
1894
1895
0
    SfxChildWindow* pChildWnd = nullptr;
1896
1897
0
    if ( comphelper::LibreOfficeKit::isActive() )
1898
0
        pChildWnd = lcl_GetChildWinFromCurrentView( m_nCurRefDlgId );
1899
0
    else
1900
0
        pChildWnd = lcl_GetChildWinFromAnyView( m_nCurRefDlgId );
1901
1902
0
    OSL_ENSURE( pChildWnd, "NoChildWin" );
1903
0
    if ( pChildWnd )
1904
0
    {
1905
0
        if (pChildWnd->GetController())
1906
0
        {
1907
0
            IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetController().get());
1908
0
            assert(pRefDlg);
1909
0
            if(pRefDlg)
1910
0
            {
1911
0
                pRefDlg->SetActive();
1912
0
            }
1913
0
        }
1914
0
    }
1915
0
}
1916
1917
/**
1918
 * Idle/OnlineSpelling
1919
 */
1920
void ScModule::EnsureIdleUpdate()
1921
1.05M
{
1922
1.05M
    if (!m_aIdleTimer.IsActive())
1923
1.24k
        m_aIdleTimer.Start(); // Restart the timer.
1924
1.05M
}
1925
1926
static void lcl_CheckNeedsRepaint( const ScDocShell* pDocShell )
1927
0
{
1928
0
    SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
1929
0
    while ( pFrame )
1930
0
    {
1931
0
        SfxViewShell* p = pFrame->GetViewShell();
1932
0
        ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( p );
1933
0
        if ( pViewSh )
1934
0
            pViewSh->CheckNeedsRepaint();
1935
0
        pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
1936
0
    }
1937
0
}
1938
1939
IMPL_LINK_NOARG(ScModule, IdleHandler, Timer *, void)
1940
1.24k
{
1941
1.24k
    if ( Application::AnyInput( VclInputFlags::MOUSE | VclInputFlags::KEYBOARD ) )
1942
0
    {
1943
0
        m_aIdleTimer.Start();
1944
0
        return;
1945
0
    }
1946
1947
1.24k
    bool bMore = false;
1948
1.24k
    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(SfxObjectShell::Current());
1949
1950
1.24k
    if ( pDocSh )
1951
0
    {
1952
0
        ScDocument& rDoc = pDocSh->GetDocument();
1953
0
        sc::DocumentLinkManager& rLinkMgr = rDoc.GetDocLinkManager();
1954
0
        bool bLinks = rLinkMgr.idleCheckLinks();
1955
0
        bool bWidth = rDoc.IdleCalcTextWidth();
1956
1957
0
        bMore = bLinks || bWidth; // Still something at all?
1958
1959
        // While calculating a Basic formula, a paint event may have occurred,
1960
        // so check the bNeedsRepaint flags for this document's views
1961
0
        if (bWidth)
1962
0
            lcl_CheckNeedsRepaint( pDocSh );
1963
0
    }
1964
1965
1.24k
    if ( bMore )
1966
0
    {
1967
0
        m_aIdleTimer.Start();
1968
0
    }
1969
1.24k
    else
1970
1.24k
    {
1971
1.24k
        m_aIdleTimer.Stop();
1972
1.24k
    }
1973
1.24k
}
1974
1975
/**
1976
 * Virtual methods for the OptionsDialog
1977
 */
1978
std::optional<SfxItemSet> ScModule::CreateItemSet( sal_uInt16 nId )
1979
0
{
1980
0
    std::optional<SfxItemSet> pRet;
1981
0
    if(SID_SC_EDITOPTIONS == nId)
1982
0
    {
1983
0
        pRet.emplace(
1984
0
            GetPool(),
1985
0
            svl::Items<
1986
                // TP_USERLISTS:
1987
0
                SCITEM_USERLIST, SCITEM_USERLIST,
1988
                // TP_GRID:
1989
0
                SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS,
1990
0
                SID_ATTR_METRIC, SID_ATTR_METRIC,
1991
0
                SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP,
1992
                // TP_INPUT:
1993
0
                SID_SC_INPUT_LEGACY_CELL_SELECTION, SID_SC_OPT_SORT_REF_UPDATE,
1994
                // TP_FORMULA, TP_DEFAULTS:
1995
0
                SID_SCFORMULAOPTIONS, SID_SCDEFAULTSOPTIONS,
1996
                // TP_VIEW, TP_CALC:
1997
0
                SID_SCVIEWOPTIONS, SID_SCDOCOPTIONS,
1998
                // TP_INPUT:
1999
0
                SID_SC_INPUT_WARNACTIVESHEET, SID_SC_INPUT_ENTER_PASTE_MODE,
2000
                // TP_PRINT:
2001
0
                SID_SCPRINTOPTIONS, SID_SCPRINTOPTIONS,
2002
                // TP_INPUT:
2003
0
                SID_SC_INPUT_SELECTION, SID_SC_INPUT_MARK_HEADER,
2004
0
                SID_SC_INPUT_TEXTWYSIWYG, SID_SC_INPUT_TEXTWYSIWYG,
2005
0
                SID_SC_INPUT_REPLCELLSWARN, SID_SC_INPUT_REPLCELLSWARN,
2006
                // TP_VIEW:
2007
0
                SID_SC_OPT_SYNCZOOM, SID_SC_OPT_KEY_BINDING_COMPAT,
2008
0
                SID_SC_OPT_LINKS, SID_SC_OPT_LINKS>);
2009
2010
0
        const ScAppOptions& rAppOpt = GetAppOptions();
2011
2012
0
        ScDocShell*     pDocSh = dynamic_cast< ScDocShell *>( SfxObjectShell::Current() );
2013
0
        ScDocOptions    aCalcOpt = pDocSh
2014
0
                            ? pDocSh->GetDocument().GetDocOptions()
2015
0
                            : GetDocOptions();
2016
2017
0
        ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( SfxViewShell::Current() );
2018
0
        ScViewOptions   aViewOpt = pViewSh
2019
0
                            ? pViewSh->GetViewData().GetOptions()
2020
0
                            : GetViewOptions();
2021
2022
0
        ScUserListItem  aULItem( SCITEM_USERLIST );
2023
0
        const ScUserList& rUL = ScGlobal::GetUserList();
2024
2025
        //  SfxGetpApp()->GetOptions( aSet );
2026
2027
0
        pRet->Put( SfxUInt16Item( SID_ATTR_METRIC,
2028
0
                        sal::static_int_cast<sal_uInt16>(rAppOpt.GetAppMetric()) ) );
2029
2030
        // TP_CALC
2031
0
        pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP,
2032
0
                        aCalcOpt.GetTabDistance()));
2033
0
        pRet->Put( ScTpCalcItem( SID_SCDOCOPTIONS, aCalcOpt ) );
2034
2035
        // TP_VIEW
2036
0
        pRet->Put( ScTpViewItem( aViewOpt ) );
2037
0
        pRet->Put( SfxBoolItem( SID_SC_OPT_SYNCZOOM, rAppOpt.GetSynchronizeZoom() ) );
2038
2039
        // TP_INPUT
2040
0
        const ScInputOptions& rInpOpt = GetInputOptions();
2041
0
        pRet->Put( SfxUInt16Item( SID_SC_INPUT_SELECTIONPOS,
2042
0
                    rInpOpt.GetMoveDir() ) );
2043
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_SELECTION,
2044
0
                    rInpOpt.GetMoveSelection() ) );
2045
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_EDITMODE,
2046
0
                    rInpOpt.GetEnterEdit() ) );
2047
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_FMT_EXPAND,
2048
0
                    rInpOpt.GetExtendFormat() ) );
2049
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_RANGEFINDER,
2050
0
                    rInpOpt.GetRangeFinder() ) );
2051
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_REF_EXPAND,
2052
0
                    rInpOpt.GetExpandRefs() ) );
2053
0
        pRet->Put( SfxBoolItem(SID_SC_OPT_SORT_REF_UPDATE, rInpOpt.GetSortRefUpdate()));
2054
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_MARK_HEADER,
2055
0
                    rInpOpt.GetMarkHeader() ) );
2056
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_TEXTWYSIWYG,
2057
0
                    rInpOpt.GetTextWysiwyg() ) );
2058
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_REPLCELLSWARN,
2059
0
                    rInpOpt.GetReplaceCellsWarn() ) );
2060
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_LEGACY_CELL_SELECTION,
2061
0
                    rInpOpt.GetLegacyCellSelection() ) );
2062
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_ENTER_PASTE_MODE,
2063
0
                    rInpOpt.GetEnterPasteMode() ) );
2064
0
        pRet->Put( SfxBoolItem( SID_SC_INPUT_WARNACTIVESHEET,
2065
0
                    rInpOpt.GetWarnActiveSheet() ) );
2066
2067
        // RID_SC_TP_PRINT
2068
0
        pRet->Put( ScTpPrintItem( GetPrintOptions() ) );
2069
2070
        // TP_GRID
2071
0
        pRet->Put( aViewOpt.CreateGridItem() );
2072
2073
        // TP_USERLISTS
2074
0
        aULItem.SetUserList(rUL);
2075
0
        pRet->Put(aULItem);
2076
2077
        // TP_COMPATIBILITY
2078
0
        pRet->Put( SfxUInt16Item( SID_SC_OPT_KEY_BINDING_COMPAT,
2079
0
                                   rAppOpt.GetKeyBindingType() ) );
2080
0
        pRet->Put( SfxBoolItem( SID_SC_OPT_LINKS, rAppOpt.GetLinksInsertedLikeMSExcel()));
2081
2082
        // TP_DEFAULTS
2083
0
        pRet->Put( ScTpDefaultsItem( GetDefaultsOptions() ) );
2084
2085
        // TP_FORMULA
2086
0
        ScFormulaOptions aOptions = GetFormulaOptions();
2087
0
        if (pDocSh)
2088
0
        {
2089
0
            ScCalcConfig aConfig( aOptions.GetCalcConfig());
2090
0
            aConfig.MergeDocumentSpecific( pDocSh->GetDocument().GetCalcConfig());
2091
0
            aOptions.SetCalcConfig( aConfig);
2092
0
        }
2093
0
        pRet->Put( ScTpFormulaItem( std::move(aOptions) ) );
2094
0
    }
2095
0
    return pRet;
2096
0
}
2097
2098
void ScModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
2099
0
{
2100
0
    if(SID_SC_EDITOPTIONS == nId)
2101
0
    {
2102
0
        ModifyOptions( rSet );
2103
0
    }
2104
0
}
2105
2106
std::unique_ptr<SfxTabPage> ScModule::CreateTabPage( sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet )
2107
0
{
2108
0
    std::unique_ptr<SfxTabPage> xRet;
2109
0
    ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2110
0
    switch(nId)
2111
0
    {
2112
0
        case SID_SC_TP_LAYOUT:
2113
0
        {
2114
0
            ::CreateTabPage ScTpLayoutOptionsCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_LAYOUT);
2115
0
            if (ScTpLayoutOptionsCreate)
2116
0
                xRet = (*ScTpLayoutOptionsCreate)(pPage, pController, &rSet);
2117
0
            break;
2118
0
        }
2119
0
        case SID_SC_TP_CONTENT:
2120
0
        {
2121
0
            ::CreateTabPage ScTpContentOptionsCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_CONTENT);
2122
0
            if (ScTpContentOptionsCreate)
2123
0
                xRet = (*ScTpContentOptionsCreate)(pPage, pController, &rSet);
2124
0
            break;
2125
0
        }
2126
0
        case SID_SC_TP_GRID:
2127
0
            xRet = SvxGridTabPage::Create(pPage, pController, rSet);
2128
0
            break;
2129
0
        case SID_SC_TP_USERLISTS:
2130
0
        {
2131
0
            ::CreateTabPage ScTpUserListsCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_USERLISTS);
2132
0
            if (ScTpUserListsCreate)
2133
0
                xRet = (*ScTpUserListsCreate)(pPage, pController, &rSet);
2134
0
            break;
2135
0
        }
2136
0
        case SID_SC_TP_CALC:
2137
0
        {
2138
0
            ::CreateTabPage ScTpCalcOptionsCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_CALC);
2139
0
            if (ScTpCalcOptionsCreate)
2140
0
                xRet = (*ScTpCalcOptionsCreate)(pPage, pController, &rSet);
2141
0
            break;
2142
0
        }
2143
0
        case SID_SC_TP_FORMULA:
2144
0
        {
2145
0
            ::CreateTabPage ScTpFormulaOptionsCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_FORMULA);
2146
0
            if (ScTpFormulaOptionsCreate)
2147
0
                xRet = (*ScTpFormulaOptionsCreate)(pPage, pController, &rSet);
2148
0
            break;
2149
0
        }
2150
0
        case SID_SC_TP_COMPATIBILITY:
2151
0
        {
2152
0
            ::CreateTabPage ScTpCompatOptionsCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_COMPATIBILITY);
2153
0
            if (ScTpCompatOptionsCreate)
2154
0
                xRet = (*ScTpCompatOptionsCreate)(pPage, pController, &rSet);
2155
0
            break;
2156
0
        }
2157
0
        case SID_SC_TP_CHANGES:
2158
0
        {
2159
0
            ::CreateTabPage ScRedlineOptionsTabPageCreate = pFact->GetTabPageCreatorFunc(SID_SC_TP_CHANGES);
2160
0
            if (ScRedlineOptionsTabPageCreate)
2161
0
                xRet =(*ScRedlineOptionsTabPageCreate)(pPage, pController, &rSet);
2162
0
            break;
2163
0
        }
2164
0
        case RID_SC_TP_PRINT:
2165
0
        {
2166
0
            ::CreateTabPage ScTpPrintOptionsCreate = pFact->GetTabPageCreatorFunc(RID_SC_TP_PRINT);
2167
0
            if (ScTpPrintOptionsCreate)
2168
0
                xRet = (*ScTpPrintOptionsCreate)(pPage, pController, &rSet);
2169
0
            break;
2170
0
        }
2171
0
        case RID_SC_TP_DEFAULTS:
2172
0
        {
2173
0
            ::CreateTabPage ScTpDefaultsOptionsCreate = pFact->GetTabPageCreatorFunc(RID_SC_TP_DEFAULTS);
2174
0
            if (ScTpDefaultsOptionsCreate)
2175
0
                xRet = (*ScTpDefaultsOptionsCreate)(pPage, pController, &rSet);
2176
0
            break;
2177
0
        }
2178
0
    }
2179
2180
0
    OSL_ENSURE( xRet, "ScModule::CreateTabPage(): no valid ID for TabPage!" );
2181
2182
0
    return xRet;
2183
0
}
2184
2185
IMPL_LINK( ScModule, CalcFieldValueHdl, EditFieldInfo*, pInfo, void )
2186
285
{
2187
    //TODO: Merge with ScFieldEditEngine!
2188
285
    if (!pInfo)
2189
0
        return;
2190
2191
285
    const SvxFieldItem& rField = pInfo->GetField();
2192
285
    const SvxFieldData* pField = rField.GetField();
2193
2194
285
    if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
2195
285
    {
2196
        // URLField
2197
285
        const OUString& aURL = pURLField->GetURL();
2198
2199
285
        switch ( pURLField->GetFormat() )
2200
285
        {
2201
0
            case SvxURLFormat::AppDefault: //TODO: Settable in the App?
2202
285
            case SvxURLFormat::Repr:
2203
285
            {
2204
285
                pInfo->SetRepresentation( pURLField->GetRepresentation() );
2205
285
            }
2206
285
            break;
2207
2208
0
            case SvxURLFormat::Url:
2209
0
            {
2210
0
                pInfo->SetRepresentation( aURL );
2211
0
            }
2212
0
            break;
2213
285
        }
2214
2215
285
        svtools::ColorConfigEntry eEntry =
2216
285
            INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
2217
285
        pInfo->SetTextColor( GetColorConfig().GetColorValue(eEntry).nColor );
2218
285
    }
2219
0
    else
2220
0
    {
2221
0
        OSL_FAIL("Unknown Field");
2222
0
        pInfo->SetRepresentation(OUString('?'));
2223
0
    }
2224
285
}
2225
2226
void ScModule::RegisterRefController(sal_uInt16 nSlotId, std::shared_ptr<SfxDialogController>& rWnd, weld::Window* pWndAncestor)
2227
0
{
2228
0
    std::vector<std::pair<std::shared_ptr<SfxDialogController>, weld::Window*>> & rlRefWindow = m_mapRefController[nSlotId];
2229
2230
0
    if (std::none_of(rlRefWindow.begin(), rlRefWindow.end(),
2231
0
                         [rWnd](const std::pair<std::shared_ptr<SfxDialogController>, weld::Window*>& rCandidate)
2232
0
                         {
2233
0
                             return rCandidate.first.get() == rWnd.get();
2234
0
                         }))
2235
0
    {
2236
0
        rlRefWindow.emplace_back(rWnd, pWndAncestor);
2237
0
    }
2238
0
}
2239
2240
void  ScModule::UnregisterRefController(sal_uInt16 nSlotId, const std::shared_ptr<SfxDialogController>& rWnd)
2241
0
{
2242
0
    auto iSlot = m_mapRefController.find( nSlotId );
2243
2244
0
    if( iSlot == m_mapRefController.end() )
2245
0
        return;
2246
2247
0
    std::vector<std::pair<std::shared_ptr<SfxDialogController>, weld::Window*>> & rlRefWindow = iSlot->second;
2248
2249
0
    auto i = std::find_if(rlRefWindow.begin(), rlRefWindow.end(),
2250
0
                            [rWnd](const std::pair<std::shared_ptr<SfxDialogController>, weld::Window*>& rCandidate)
2251
0
                            {
2252
0
                                return rCandidate.first.get() == rWnd.get();
2253
0
                            });
2254
2255
0
    if( i == rlRefWindow.end() )
2256
0
        return;
2257
2258
0
    rlRefWindow.erase( i );
2259
2260
0
    if( rlRefWindow.empty() )
2261
0
        m_mapRefController.erase( nSlotId );
2262
0
}
2263
2264
std::shared_ptr<SfxDialogController> ScModule::Find1RefWindow(sal_uInt16 nSlotId, const weld::Window *pWndAncestor)
2265
0
{
2266
0
    if (!pWndAncestor)
2267
0
        return nullptr;
2268
2269
0
    auto iSlot = m_mapRefController.find( nSlotId );
2270
2271
0
    if( iSlot == m_mapRefController.end() )
2272
0
        return nullptr;
2273
2274
0
    std::vector<std::pair<std::shared_ptr<SfxDialogController>, weld::Window*>> & rlRefWindow = iSlot->second;
2275
2276
0
    for (auto const& refWindow : rlRefWindow)
2277
0
        if ( refWindow.second == pWndAncestor )
2278
0
            return refWindow.first;
2279
2280
0
    return nullptr;
2281
0
}
2282
2283
using namespace com::sun::star;
2284
2285
constexpr OUStringLiteral LINGUPROP_AUTOSPELL = u"IsSpellAuto";
2286
2287
void ScModule::GetSpellSettings( LanguageType& rDefLang, LanguageType& rCjkLang, LanguageType& rCtlLang )
2288
39.2k
{
2289
    // use SvtLinguConfig instead of service LinguProperties to avoid
2290
    // loading the linguistic component
2291
39.2k
    SvtLinguConfig aConfig;
2292
2293
39.2k
    SvtLinguOptions aOptions;
2294
39.2k
    aConfig.GetOptions( aOptions );
2295
2296
39.2k
    rDefLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage, css::i18n::ScriptType::LATIN);
2297
39.2k
    rCjkLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CJK, css::i18n::ScriptType::ASIAN);
2298
39.2k
    rCtlLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CTL, css::i18n::ScriptType::COMPLEX);
2299
39.2k
}
2300
2301
void ScModule::SetAutoSpellProperty( bool bSet )
2302
0
{
2303
    // use SvtLinguConfig instead of service LinguProperties to avoid
2304
    // loading the linguistic component
2305
0
    SvtLinguConfig aConfig;
2306
2307
0
    aConfig.SetProperty( LINGUPROP_AUTOSPELL, uno::Any(bSet) );
2308
0
}
2309
2310
bool ScModule::GetAutoSpellProperty()
2311
0
{
2312
    // use SvtLinguConfig instead of service LinguProperties to avoid
2313
    // loading the linguistic component
2314
0
    SvtLinguConfig aConfig;
2315
2316
0
    SvtLinguOptions aOptions;
2317
0
    aConfig.GetOptions( aOptions );
2318
2319
0
    return aOptions.bIsSpellAuto;
2320
0
}
2321
2322
bool ScModule::HasThesaurusLanguage( LanguageType nLang )
2323
0
{
2324
0
    if ( nLang == LANGUAGE_NONE )
2325
0
        return false;
2326
2327
0
    bool bHasLang = false;
2328
0
    try
2329
0
    {
2330
0
        uno::Reference< linguistic2::XThesaurus > xThes(LinguMgr::GetThesaurus());
2331
0
        if ( xThes.is() )
2332
0
            bHasLang = xThes->hasLocale( LanguageTag::convertToLocale( nLang ) );
2333
0
    }
2334
0
    catch( uno::Exception& )
2335
0
    {
2336
0
        OSL_FAIL("Error in Thesaurus");
2337
0
    }
2338
2339
0
    return bHasLang;
2340
0
}
2341
2342
SfxStyleFamilies ScModule::CreateStyleFamilies()
2343
0
{
2344
0
    SfxStyleFamilies aStyleFamilies;
2345
0
    std::locale resLocale = ScModule::get()->GetResLocale();
2346
2347
0
    aStyleFamilies.emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Para,
2348
0
                                                    ScResId(STR_STYLE_FAMILY_CELL),
2349
0
                                                    BMP_STYLES_FAMILY_CELL,
2350
0
                                                    RID_CELLSTYLEFAMILY, resLocale));
2351
2352
0
    aStyleFamilies.emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Page,
2353
0
                                                    ScResId(STR_STYLE_FAMILY_PAGE),
2354
0
                                                    BMP_STYLES_FAMILY_PAGE,
2355
0
                                                    RID_PAGESTYLEFAMILY, resLocale));
2356
2357
0
    aStyleFamilies.emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Frame,
2358
0
                                                    ScResId(STR_STYLE_FAMILY_GRAPHICS),
2359
0
                                                    BMP_STYLES_FAMILY_GRAPHICS,
2360
0
                                                    RID_GRAPHICSTYLEFAMILY, resLocale));
2361
2362
0
    return aStyleFamilies;
2363
0
}
2364
2365
void ScModule::RegisterAutomationApplicationEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const& xCaller)
2366
0
{
2367
0
    mxAutomationApplicationEventsCaller = xCaller;
2368
0
}
2369
2370
void ScModule::CallAutomationApplicationEventSinks(const OUString& Method, css::uno::Sequence< css::uno::Any >& Arguments)
2371
0
{
2372
0
    if (mxAutomationApplicationEventsCaller.is())
2373
0
        mxAutomationApplicationEventsCaller->CallSinks(Method, Arguments);
2374
0
}
2375
2376
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */