Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/appl/appserv.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <config_features.h>
21
#include <config_wasm_strip.h>
22
23
#include <com/sun/star/deployment/ui/PackageManagerDialog.hpp>
24
#include <com/sun/star/drawing/ModuleDispatcher.hpp>
25
#include <com/sun/star/frame/Desktop.hpp>
26
#include <com/sun/star/frame/DispatchResultEvent.hpp>
27
#include <com/sun/star/frame/DispatchResultState.hpp>
28
#include <com/sun/star/frame/DispatchHelper.hpp>
29
#include <com/sun/star/frame/UnknownModuleException.hpp>
30
#include <com/sun/star/frame/XLayoutManager.hpp>
31
#include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
32
#include <com/sun/star/embed/EmbedStates.hpp>
33
#include <com/sun/star/embed/XEmbeddedObject.hpp>
34
#include <com/sun/star/util/XModifiable.hpp>
35
#include <com/sun/star/sdbc/DriverManager.hpp>
36
#include <com/sun/star/text/ModuleDispatcher.hpp>
37
#include <com/sun/star/task/OfficeRestartManager.hpp>
38
#include <com/sun/star/task/XInteractionHandler.hpp>
39
#include <com/sun/star/ui/dialogs/AddressBookSourcePilot.hpp>
40
#include <com/sun/star/ui/UIElementType.hpp>
41
#include <com/sun/star/ui/XUIElement.hpp>
42
#include <com/sun/star/uno/Reference.hxx>
43
#include <com/sun/star/util/XCloseable.hpp>
44
#include <com/sun/star/util/CloseVetoException.hpp>
45
#include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
46
47
#include <comphelper/dispatchcommand.hxx>
48
#include <comphelper/lok.hxx>
49
#include <comphelper/namedvaluecollection.hxx>
50
#include <comphelper/processfactory.hxx>
51
#include <comphelper/propertysequence.hxx>
52
#include <comphelper/propertyvalue.hxx>
53
#include <comphelper/sequence.hxx>
54
#include <comphelper/sequenceashashmap.hxx>
55
56
#include <svtools/addresstemplate.hxx>
57
#include <svtools/restartdialog.hxx>
58
#include <svtools/colorcfg.hxx>
59
#include <svl/visitem.hxx>
60
61
#include <unotools/configmgr.hxx>
62
#include <comphelper/diagnose_ex.hxx>
63
#include <vcl/weld/DialogController.hxx>
64
#include <vcl/weld/MessageDialog.hxx>
65
#include <svl/intitem.hxx>
66
#include <svl/eitem.hxx>
67
#include <svl/stritem.hxx>
68
#include <basic/sbstar.hxx>
69
#include <basic/basrdll.hxx>
70
#include <basic/sberrors.hxx>
71
#include <tools/debug.hxx>
72
#include <vcl/help.hxx>
73
#include <sal/log.hxx>
74
#include <osl/file.hxx>
75
#include <vcl/EnumContext.hxx>
76
#include <vcl/themecolors.hxx>
77
#include <vcl/svapp.hxx>
78
79
#include <unotools/moduleoptions.hxx>
80
#include <unotools/securityoptions.hxx>
81
#include <rtl/bootstrap.hxx>
82
83
#include <com/sun/star/frame/ModuleManager.hpp>
84
#include <com/sun/star/frame/XModel3.hpp>
85
#include <com/sun/star/beans/XPropertySet.hpp>
86
87
#include <sfx2/AdditionsDialogHelper.hxx>
88
#include <sfx2/app.hxx>
89
#include <sfx2/request.hxx>
90
#include <sfx2/dispatch.hxx>
91
#include <sfx2/bindings.hxx>
92
#include <sfx2/minfitem.hxx>
93
#include <sfx2/msg.hxx>
94
#include <sfx2/objface.hxx>
95
#include <sfx2/objsh.hxx>
96
#include <sfx2/viewsh.hxx>
97
#include <sfx2/docfac.hxx>
98
#include <sfx2/strings.hrc>
99
#include <sfx2/sfxresid.hxx>
100
#include <appdata.hxx>
101
#include <sfx2/viewfrm.hxx>
102
#include <sfx2/sfxdlg.hxx>
103
#include <sfx2/sfxsids.hrc>
104
#include <sorgitm.hxx>
105
#include <sfx2/sfxhelp.hxx>
106
#include <sfx2/zoomitem.hxx>
107
#include <sfx2/templatedlg.hxx>
108
#include <sfx2/notebookbar/SfxNotebookBar.hxx>
109
#include <sfx2/sidebar/SidebarController.hxx>
110
#include <sfx2/safemode.hxx>
111
#include <sfx2/sfxuno.hxx>
112
#include <DevelopmentToolDockingWindow.hxx>
113
114
#include <comphelper/types.hxx>
115
#include <officecfg/Office/Common.hxx>
116
#include <officecfg/Setup.hxx>
117
#include <unotools/confignode.hxx>
118
#include <memory>
119
120
#include <openuriexternally.hxx>
121
122
#include "getbasctlfunction.hxx"
123
124
using namespace ::com::sun::star;
125
using namespace ::com::sun::star::beans;
126
using namespace ::com::sun::star::uno;
127
using namespace ::com::sun::star::frame;
128
using namespace ::com::sun::star::container;
129
using namespace ::com::sun::star::util;
130
using namespace ::com::sun::star::lang;
131
using namespace ::com::sun::star::ui;
132
133
namespace
134
{
135
    OUString lcl_getAppName( vcl::EnumContext::Application eApp )
136
0
    {
137
0
        switch ( eApp )
138
0
        {
139
0
            case vcl::EnumContext::Application::Writer:
140
0
                return u"Writer"_ustr;
141
0
            case vcl::EnumContext::Application::Calc:
142
0
                return u"Calc"_ustr;
143
0
            case vcl::EnumContext::Application::Impress:
144
0
                return u"Impress"_ustr;
145
0
            case vcl::EnumContext::Application::Draw:
146
0
                return u"Draw"_ustr;
147
0
            case vcl::EnumContext::Application::Formula:
148
0
                return u"Formula"_ustr;
149
0
            case vcl::EnumContext::Application::Base:
150
0
                return u"Base"_ustr;
151
0
            default:
152
0
                return OUString();
153
0
        }
154
0
    }
155
156
    // lp#527938, debian#602953, fdo#33266, i#105408
157
    bool lcl_isBaseAvailable()
158
0
    {
159
0
        try
160
0
        {
161
            // if we get css::sdbc::DriverManager, libsdbc2 is there
162
            // and the bibliography is assumed to work
163
0
            return css::sdbc::DriverManager::create(comphelper::getProcessComponentContext()).is();
164
0
        }
165
0
        catch (const Exception &)
166
0
        {
167
0
            TOOLS_INFO_EXCEPTION("sfx.appl", "assuming Base to be missing");
168
0
            return false;
169
0
        }
170
0
    }
171
    void lcl_tryLoadBibliography()
172
0
    {
173
        // lp#527938, debian#602953, fdo#33266, i#105408
174
        // make sure we actually can instantiate services from base first
175
0
        if(!lcl_isBaseAvailable())
176
0
        {
177
0
            if (officecfg::Office::Common::PackageKit::EnableBaseInstallation::get())
178
0
            {
179
0
                try
180
0
                {
181
0
                    using namespace org::freedesktop::PackageKit;
182
0
                    using namespace svtools;
183
0
                    Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
184
0
                    Sequence< OUString > vPackages { u"libreoffice-base"_ustr };
185
0
                    xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString());
186
                    // I'll be back (hopefully)!
187
0
                    SolarMutexGuard aGuard;
188
0
                    executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_BIBLIOGRAPHY_INSTALL);
189
0
                }
190
0
                catch (const Exception &)
191
0
                {
192
0
                    TOOLS_INFO_EXCEPTION("sfx.appl", "trying to install LibreOffice Base");
193
0
                }
194
0
            }
195
0
            return;
196
0
        }
197
198
0
        try // fdo#48775
199
0
        {
200
0
            SfxStringItem aURL(SID_FILE_NAME, u".component:Bibliography/View1"_ustr);
201
0
            SfxStringItem aRef(SID_REFERER, u"private:user"_ustr);
202
0
            SfxStringItem aTarget(SID_TARGETNAME, u"_blank"_ustr);
203
0
            if (const SfxViewFrame* pViewFrame = SfxViewFrame::Current())
204
0
            {
205
0
                pViewFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
206
0
                        SfxCallMode::ASYNCHRON, { &aURL, &aRef, &aTarget });
207
0
            }
208
0
        }
209
0
        catch (const Exception &)
210
0
        {
211
0
            TOOLS_INFO_EXCEPTION( "sfx.appl", "trying to load bibliography database");
212
0
        }
213
0
    }
214
    void lcl_disableActiveEmbeddedObjects(const SfxObjectShell* pObjSh)
215
0
    {
216
0
        if (!pObjSh)
217
0
            return;
218
219
0
        comphelper::EmbeddedObjectContainer& rContainer = pObjSh->getEmbeddedObjectContainer();
220
0
        if (!rContainer.HasEmbeddedObjects())
221
0
            return;
222
223
0
        const uno::Sequence<OUString> aNames = rContainer.GetObjectNames();
224
0
        for (const auto& rName : aNames)
225
0
        {
226
0
            uno::Reference<embed::XEmbeddedObject> xEmbeddedObj
227
0
                = rContainer.GetEmbeddedObject(rName);
228
0
            if (!xEmbeddedObj.is())
229
0
                continue;
230
231
0
            try
232
0
            {
233
0
                if (xEmbeddedObj->getCurrentState() != embed::EmbedStates::LOADED)
234
0
                {
235
0
                    xEmbeddedObj->changeState(embed::EmbedStates::LOADED);
236
0
                }
237
0
            }
238
0
            catch (const uno::Exception&)
239
0
            {
240
0
            }
241
0
        }
242
0
    }
243
}
244
/// Find the correct location of the document (CREDITS.fodt, etc.), and return
245
/// it in rURL if found.
246
static bool checkURL( const char *pName, const char *pExt, OUString &rURL )
247
0
{
248
0
    using namespace osl;
249
0
    DirectoryItem aDirItem;
250
251
#ifdef MACOSX
252
    rURL = "$BRAND_BASE_DIR/Resources/" + OUString::createFromAscii( pName ) +
253
           OUString::createFromAscii( pExt );
254
#else
255
0
    rURL = "$BRAND_BASE_DIR/" + OUString::createFromAscii( pName ) +
256
0
           OUString::createFromAscii( pExt );
257
0
#endif
258
0
    rtl::Bootstrap::expandMacros( rURL );
259
260
0
    if (!rURL.isEmpty())
261
0
        return DirectoryItem::get( rURL, aDirItem ) == DirectoryItem::E_None;
262
0
    else
263
0
        return false;
264
0
}
265
266
/// Displays CREDITS or LICENSE in any of the available version
267
static void showDocument( const char* pBaseName )
268
0
{
269
0
    try {
270
0
        Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
271
0
        auto args(::comphelper::InitPropertySequence({
272
0
            {"ViewOnly",    Any(true)},
273
0
            {"ReadOnly",    Any(true)}
274
0
        }));
275
276
0
        OUString aURL;
277
0
        if ( checkURL ( pBaseName, ".fodt", aURL ) ||
278
0
             checkURL ( pBaseName, ".html", aURL ) ||
279
0
             checkURL ( pBaseName, "", aURL ) ) {
280
0
            xDesktop->loadComponentFromURL( aURL, u"_blank"_ustr, 0, args );
281
0
        }
282
0
    } catch (const css::uno::Exception &) {
283
0
    }
284
0
}
285
286
namespace
287
{
288
    Reference<XFrame> GetRequestFrame(const SfxRequest& rReq)
289
0
    {
290
0
        const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
291
0
        const SfxUnoFrameItem* pItem = nullptr;
292
0
        Reference <XFrame> xFrame;
293
0
        if (pArgs && (pItem = pArgs->GetItemIfSet(SID_FILLFRAME, false)))
294
0
        {
295
0
            xFrame = pItem->GetFrame();
296
0
        }
297
0
        return xFrame;
298
0
    }
299
300
    Reference<XFrame> GetDocFrame(const SfxRequest& rReq)
301
0
    {
302
0
        const SfxFrameItem* pFrameItem = rReq.GetArg<SfxFrameItem>(SID_DOCFRAME);
303
0
        SfxFrame* pFrame = pFrameItem ? pFrameItem->GetFrame() : nullptr;
304
0
        return pFrame ? pFrame->GetFrameInterface() : nullptr;
305
0
    }
306
307
    class LicenseDialog : public weld::GenericDialogController
308
    {
309
    public:
310
        LicenseDialog(weld::Window* pParent)
311
0
            : GenericDialogController(pParent, u"sfx/ui/licensedialog.ui"_ustr,  u"LicenseDialog"_ustr)
312
0
        {
313
0
        }
314
315
        virtual short run() override
316
0
        {
317
0
            short nRet = GenericDialogController::run();
318
0
            if (nRet == RET_OK)
319
0
                showDocument("LICENSE");
320
0
            return nRet;
321
0
        }
322
    };
323
324
    class SafeModeQueryDialog : public weld::MessageDialogController
325
    {
326
    public:
327
        SafeModeQueryDialog(weld::Window* pParent)
328
0
            : MessageDialogController(pParent, u"sfx/ui/safemodequerydialog.ui"_ustr, u"SafeModeQueryDialog"_ustr)
329
0
        {
330
0
        }
331
332
        virtual short run() override
333
0
        {
334
0
            short nRet = MessageDialogController::run();
335
0
            if (nRet == RET_OK)
336
0
            {
337
0
                sfx2::SafeMode::putFlag();
338
0
                const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext();
339
0
                css::task::OfficeRestartManager::get(xContext)->requestRestart(
340
0
                    css::uno::Reference< css::task::XInteractionHandler >());
341
0
            }
342
0
            return nRet;
343
0
        }
344
    };
345
}
346
347
weld::Window* SfxRequest::GetFrameWeld() const
348
0
{
349
0
    const SfxItemSet* pIntArgs = GetInternalArgs_Impl();
350
0
    const SfxUnoAnyItem* pItem = nullptr;
351
0
    if (pIntArgs && (pItem = pIntArgs->GetItemIfSet(SID_DIALOG_PARENT, false)))
352
0
    {
353
0
        Reference<awt::XWindow> xWindow;
354
0
        pItem->GetValue() >>= xWindow;
355
0
        return Application::GetFrameWeld(xWindow);
356
0
    }
357
358
0
    Reference<XFrame> xFrame(GetRequestFrame(*this));
359
0
    if (!xFrame)
360
0
        xFrame = GetDocFrame(*this);
361
0
    if (!xFrame)
362
0
    {
363
0
        SAL_WARN("sfx.appl", "no parent for dialogs");
364
0
        return nullptr;
365
0
    }
366
0
    return Application::GetFrameWeld(xFrame->getContainerWindow());
367
0
}
368
369
void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
370
0
{
371
0
    const bool bIsLOK = comphelper::LibreOfficeKit::isActive();
372
0
    static svtools::EditableColorConfig aEditableConfig;
373
0
    static bool aColorConfigInitialized = false;
374
0
    if (!aColorConfigInitialized && bIsLOK)
375
0
    {
376
        // preload color schemes
377
0
        aEditableConfig.LoadScheme("Light");
378
0
        aEditableConfig.LoadScheme("Dark");
379
0
        aColorConfigInitialized = true;
380
0
    }
381
382
0
    bool bDone = false;
383
0
    switch ( rReq.GetSlot() )
384
0
    {
385
0
        case SID_SETOPTIONS:
386
0
        {
387
0
            if( rReq.GetArgs() )
388
0
                SetOptions( *rReq.GetArgs() );
389
0
            break;
390
0
        }
391
392
0
        case SID_QUITAPP:
393
0
        case SID_LOGOUT:
394
0
        {
395
            // protect against reentrant calls and avoid closing the same files in parallel
396
0
            if (pImpl->bInQuit || pImpl->bClosingDocs)
397
0
                return;
398
399
0
            if ( rReq.GetSlot() == SID_LOGOUT )
400
0
            {
401
0
                for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
402
0
                    pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
403
0
                {
404
0
                    if ( !pObjSh->IsModified() )
405
0
                        continue;
406
407
0
                    SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
408
0
                    if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
409
0
                        continue;
410
411
0
                    if (pObjSh->PrepareClose())
412
0
                        pObjSh->SetModified( false );
413
0
                    else
414
0
                        return;
415
0
                }
416
417
0
                SfxStringItem aNameItem( SID_FILE_NAME, u"vnd.sun.star.cmd:logout"_ustr );
418
0
                SfxStringItem aReferer( SID_REFERER, u"private/user"_ustr );
419
0
                pImpl->pAppDispat->ExecuteList(SID_OPENDOC,
420
0
                        SfxCallMode::SLOT, { &aNameItem, &aReferer });
421
0
                return;
422
0
            }
423
424
            // try from nested requests again after 100ms
425
0
            if( Application::GetDispatchLevel() > 1 )
426
0
            {
427
                /* Don't save the request for closing the application and try it later
428
                   again. This is an UI bound functionality ... and the user will  try it again
429
                   if the dialog is closed. But we should not close the application automatically
430
                   if this dialog is closed by the user ...
431
                   So we ignore this request now and wait for a new user decision.
432
                */
433
0
                SAL_INFO("sfx.appl", "QueryExit => sal_False, DispatchLevel == " << Application::GetDispatchLevel() );
434
0
                return;
435
0
            }
436
437
            // block reentrant calls
438
0
            pImpl->bInQuit = true;
439
0
            Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
440
441
0
            rReq.ForgetAllArgs();
442
443
            // if terminate() failed, pImpl->bInQuit will now be sal_False, allowing further calls of SID_QUITAPP
444
0
            bool bTerminated = xDesktop->terminate();
445
0
            if (!bTerminated)
446
                // if terminate() was successful, SfxApplication is now dead!
447
0
                pImpl->bInQuit = false;
448
449
            // Set return value, terminate if possible
450
0
            rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
451
0
            return;
452
0
        }
453
454
0
        case SID_CONFIG:
455
0
        case SID_TOOLBOXOPTIONS:
456
0
        case SID_CONFIGSTATUSBAR:
457
0
        case SID_CONFIGMENU:
458
0
        case SID_CONFIGACCEL:
459
0
        case SID_CONFIGEVENT:
460
0
        {
461
0
            SfxAbstractDialogFactory* pFact =
462
0
                SfxAbstractDialogFactory::Create();
463
464
0
            const SfxStringItem* pStringItem = rReq.GetArg(SID_CONFIG);
465
466
0
            SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<SID_CONFIG, SID_CONFIG, SID_MACROINFO, SID_MACROINFO>( GetPool() ));
467
468
            // SID_CONFIG property will determine the default page shown
469
0
            if ( pStringItem )
470
0
            {
471
0
                aSet.Put( SfxStringItem(
472
0
                    SID_CONFIG, pStringItem->GetValue() ) );
473
0
            }
474
0
            else if (rReq.GetSlot() == SID_CONFIGEVENT)
475
0
            {
476
0
                aSet.Put( SfxStringItem(
477
0
                    SID_CONFIG, u"private:resource/event/"_ustr ) );
478
0
            }
479
0
            else if (rReq.GetSlot() == SID_TOOLBOXOPTIONS)
480
0
            {
481
0
                aSet.Put( SfxStringItem(
482
0
                    SID_CONFIG, u"private:resource/toolbar/"_ustr ) );
483
0
            }
484
485
#if HAVE_FEATURE_SCRIPTING
486
            // Preselect a macro in the 'keyboard' page
487
            if (auto const item = rReq.GetArg(SID_MACROINFO)) {
488
                aSet.Put(*item);
489
            }
490
#endif
491
492
0
            Reference <XFrame> xFrame(GetRequestFrame(rReq));
493
0
            ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateCustomizeTabDialog(rReq.GetFrameWeld(),
494
0
                &aSet, xFrame ));
495
496
0
            const short nRet = pDlg->Execute();
497
498
0
            if ( nRet )
499
0
                bDone = true;
500
0
            break;
501
0
        }
502
503
0
        case SID_CLOSEDOCS:
504
0
        {
505
            // protect against reentrant calls and avoid closing the same files in parallel
506
0
            if (pImpl->bInQuit || pImpl->bClosingDocs)
507
0
                return;
508
509
0
            pImpl->bClosingDocs = true;
510
            // closed all status for all visible frames
511
0
            bool bClosedAll = true;
512
513
            // Iterate over all documents and close them
514
0
            for (SfxObjectShell *pObjSh = SfxObjectShell::GetFirst(); pObjSh;)
515
0
            {
516
0
                SfxObjectShell* pNxtObjSh = SfxObjectShell::GetNext(*pObjSh);
517
                // can close immediately
518
0
                if (!pObjSh->IsModified())
519
0
                {
520
                    // don't close the last remaining frame for close dispatch
521
0
                    if (pNxtObjSh || !bClosedAll)
522
0
                        pObjSh->DoClose();
523
0
                }
524
0
                else
525
0
                {
526
                    // skip invisible frames when asking user to close
527
0
                    SfxViewFrame* pFrame = SfxViewFrame::GetFirst(pObjSh);
528
0
                    if (pFrame && pFrame->GetWindow().IsReallyVisible())
529
0
                    {
530
                        // asks user to close
531
0
                        if (pObjSh->PrepareClose())
532
0
                        {
533
0
                            pObjSh->SetModified(false);
534
                            // get next pointer again after asking user since it can become invalid pointer from being manually closed by user
535
                            // don't close the last remaining frame for close dispatch
536
0
                            if ((pNxtObjSh = SfxObjectShell::GetNext(*pObjSh)) || !bClosedAll)
537
0
                                pObjSh->DoClose();
538
0
                        }
539
                        // user disagrees to close
540
0
                        else
541
0
                        {
542
0
                            bClosedAll = false;
543
                            // get next pointer again after asking user since it can become invalid pointer from being manually closed by user
544
0
                            pNxtObjSh = SfxObjectShell::GetNext(*pObjSh);
545
0
                        }
546
0
                    }
547
0
                }
548
0
                pObjSh = pNxtObjSh;
549
0
            }
550
551
0
            pImpl->bClosingDocs = false;
552
553
            // close dispatch status
554
0
            bool bDispatchOk = true;
555
            // open backing window
556
0
            if (bClosedAll)
557
0
            {
558
                // don't use pViewFrame = SfxViewFrame::Current() as dispatch won't load sometimes
559
0
                SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
560
0
                SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(pObjSh);
561
0
                if (pViewFrame)
562
0
                {
563
0
                    Reference<XFrame> xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
564
0
                    if (xCurrentFrame.is())
565
0
                    {
566
0
                        uno::Reference<frame::XDispatchProvider> xProvider(xCurrentFrame, uno::UNO_QUERY);
567
0
                        if (xProvider.is())
568
0
                        {
569
0
                            uno::Reference<frame::XDispatchHelper> xDispatcher
570
0
                                = frame::DispatchHelper::create(::comphelper::getProcessComponentContext());
571
                            // use .uno:CloseDoc to be able to close windows of the same document
572
0
                            css::uno::Any aResult =
573
0
                                xDispatcher->executeDispatch(xProvider,
574
0
                                                             u".uno:CloseDoc"_ustr,
575
0
                                                             u"_self"_ustr,
576
0
                                                             0,
577
0
                                                             uno::Sequence<beans::PropertyValue>());
578
0
                            css::frame::DispatchResultEvent aEvent;
579
0
                            bDispatchOk = (aResult >>= aEvent) && (aEvent.State == frame::DispatchResultState::SUCCESS);
580
0
                        }
581
0
                    }
582
0
                }
583
0
            }
584
            // terminate the application if the dispatch fails or
585
            // if there is no visible frame left after the command is run (e.g user manually closes the document again that was already cancelled for closing)
586
0
            if (!bDispatchOk || (!bClosedAll && !SfxObjectShell::GetFirst()))
587
0
            {
588
0
                SfxRequest aReq(SID_QUITAPP, SfxCallMode::SLOT, GetPool());
589
0
                MiscExec_Impl(aReq);
590
0
            }
591
592
0
            rReq.SetReturnValue(SfxBoolItem(0, bDispatchOk));
593
0
            bDone = true;
594
0
            break;
595
0
        }
596
597
0
        case SID_SAVEDOCS:
598
0
        {
599
0
            bool bOK = true;
600
0
            for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
601
0
                  pObjSh;
602
0
                  pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
603
0
            {
604
0
                SfxRequest aReq( SID_SAVEDOC, SfxCallMode::SLOT, pObjSh->GetPool() );
605
0
                if ( pObjSh->IsModified() && !pObjSh->isSaveLocked() )
606
0
                {
607
0
                    pObjSh->ExecuteSlot( aReq );
608
0
                    const SfxBoolItem* pItem(dynamic_cast<const SfxBoolItem*>(aReq.GetReturnValue().getItem()));
609
0
                    if ( !pItem || !pItem->GetValue() )
610
0
                        bOK = false;
611
0
                }
612
0
            }
613
614
0
            rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
615
0
            rReq.Done();
616
0
            break;
617
0
        }
618
619
0
        case SID_SEND_FEEDBACK:
620
0
        {
621
0
            OUString module = SfxHelp::GetCurrentModuleIdentifier();
622
0
            OUString sURL(officecfg::Office::Common::Menus::SendFeedbackURL::get() + //officecfg/registry/data/org/openoffice/Office/Common.xcu => https://hub.libreoffice.org/send-feedback/
623
0
                "?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
624
0
                "&LOlocale=" + utl::ConfigManager::getUILocale() +
625
0
                "&LOmodule=" + module.subView(module.lastIndexOf('.') + 1 )  );
626
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
627
0
            break;
628
0
        }
629
630
0
        case SID_Q_AND_A:
631
0
        {
632
            // Askbot has URL's normalized to languages, not locales
633
            // Get language from locale: ll or lll or ll-CC or lll-CC
634
635
0
            OUString sURL(officecfg::Office::Common::Menus::QA_URL::get() + //https://hub.libreoffice.org/forum/
636
0
                "?LOlocale=" + utl::ConfigManager::getUILocale());
637
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
638
0
            break;
639
0
        }
640
0
        case SID_DOCUMENTATION:
641
0
        {
642
            // Open documentation page based on locales
643
0
            OUString sURL(officecfg::Office::Common::Menus::DocumentationURL::get() + //https://hub.libreoffice.org/documentation/
644
0
                "?LOlocale=" + utl::ConfigManager::getUILocale());
645
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
646
0
            break;
647
0
        }
648
0
#if !ENABLE_WASM_STRIP_PINGUSER
649
0
        case SID_GETINVOLVED:
650
0
        {
651
            // Open get involved/join us page based on locales
652
0
            OUString sURL(officecfg::Office::Common::Menus::GetInvolvedURL::get() + //https://hub.libreoffice.org/joinus/
653
0
                "?LOlocale=" + utl::ConfigManager::getUILocale());
654
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
655
0
            break;
656
0
        }
657
0
        case SID_DONATION:
658
0
        {
659
            // Open donation page based on language + script (BCP47) with language as fall back.
660
0
            OUString aLang = LanguageTag(utl::ConfigManager::getUILocale()).getLanguage();
661
0
            OUString aBcp47 = LanguageTag(utl::ConfigManager::getUILocale()).getBcp47();
662
0
            OUString sURL(officecfg::Office::Common::Menus::DonationURL::get() + //https://hub.libreoffice.org/donation/
663
0
                "?BCP47=" + aBcp47 + "&LOlang=" + aLang );
664
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
665
0
            break;
666
0
        }
667
0
        case SID_WHATSNEW:
668
0
        {
669
            // Open release notes depending on version and locale
670
0
            OUString sURL(officecfg::Office::Common::Menus::ReleaseNotesURL::get() + //https://hub.libreoffice.org/ReleaseNotes/
671
0
                "?LOvers=" + utl::ConfigManager::getProductVersion() +
672
0
                "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47() );
673
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
674
0
            break;
675
0
        }
676
0
        case SID_CREDITS:
677
0
        {
678
0
            OUString sURL(officecfg::Office::Common::Menus::CreditsURL::get());
679
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
680
0
            break;
681
0
        }
682
0
        break;
683
0
        case SID_HYPHENATIONMISSING:
684
0
        {
685
            // Open wiki page about hyphenation
686
0
            OUString sURL(officecfg::Office::Common::Menus::HyphenationMissingURL::get() + //https://hub.libreoffice.org/HyphenationMissing/
687
0
                "?LOlocale=" + utl::ConfigManager::getUILocale());
688
0
            sfx2::openUriExternally(sURL, false, rReq.GetFrameWeld());
689
0
            break;
690
0
        }
691
0
#endif
692
0
        case SID_SHOW_LICENSE:
693
0
        {
694
0
            LicenseDialog aDialog(rReq.GetFrameWeld());
695
0
            aDialog.run();
696
0
            break;
697
0
        }
698
699
0
        case SID_SHOW_CREDITS:
700
0
        {
701
0
            showDocument( "CREDITS" );
702
0
            break;
703
0
        }
704
705
0
        case FN_CHANGE_THEME:
706
0
        {
707
0
            const SfxStringItem* pNewThemeArg = rReq.GetArg(FN_PARAM_NEW_THEME);
708
0
            OUString sSchemeName = ThemeColors::GetThemeColors().GetThemeName();
709
0
            AppearanceMode eAppearnceMode = MiscSettings::GetAppColorMode();
710
711
0
            if (!pNewThemeArg)
712
0
            {
713
                // we do not override custom themes if the unocommand was triggered from the UI
714
                // by clicking on a toolbar/notebookbar button for example.
715
0
                if (!ThemeColors::IsCustomTheme(sSchemeName))
716
0
                {
717
0
                    bool bChangeToLightTheme = eAppearnceMode == AppearanceMode::DARK
718
0
                                               || (eAppearnceMode == AppearanceMode::AUTO
719
0
                                                   && MiscSettings::GetUseDarkMode());
720
721
                    // note that a theme and an appearance mode are not orthogonal anymore, for
722
                    // "Custom Themes", appearance mode is AUTO, for the "Automatic", "Light" and
723
                    // "Dark" default themes, it's AUTO, LIGHT & DARK respectively.
724
0
                    if (bChangeToLightTheme)
725
0
                    {
726
0
                        sSchemeName = svtools::LIGHT_COLOR_SCHEME;
727
0
                        eAppearnceMode = AppearanceMode::LIGHT;
728
0
                    }
729
0
                    else
730
0
                    {
731
0
                        sSchemeName = svtools::DARK_COLOR_SCHEME;
732
0
                        eAppearnceMode = AppearanceMode::DARK;
733
0
                    }
734
0
                }
735
0
            }
736
0
            else
737
0
                sSchemeName = pNewThemeArg->GetValue();
738
739
0
            aEditableConfig.LoadScheme(sSchemeName);
740
0
            MiscSettings::SetAppColorMode(eAppearnceMode);
741
742
            // kit explicitly ignores changes to the global color scheme, except for the current ViewShell,
743
            // so an attempted change to the same global color scheme when the now current ViewShell ignored
744
            // the last change requires re-sending the change. In which case individual shells will have to
745
            // decide if this color-scheme change is a change from their perspective to avoid unnecessary
746
            // invalidations.
747
0
            if (!pNewThemeArg || bIsLOK || aEditableConfig.GetCurrentSchemeName() != sSchemeName)
748
0
            {
749
0
                if (bIsLOK)
750
0
                    aEditableConfig.SetCurrentSchemeName(sSchemeName);
751
0
                else
752
0
                    aEditableConfig.LoadScheme(sSchemeName);
753
0
            }
754
755
0
            Invalidate(FN_CHANGE_THEME);
756
0
            break;
757
0
        }
758
0
        case FN_INVERT_BACKGROUND:
759
0
        {
760
0
            const SfxStringItem* pNewThemeArg = rReq.GetArg(FN_PARAM_NEW_THEME);
761
762
0
            svtools::EditableColorConfig aColorConfig;
763
0
            ::Color aDefLightColor = svtools::ColorConfig::GetDefaultColor(svtools::DOCCOLOR, 0);
764
0
            ::Color aDefDarkColor = svtools::ColorConfig::GetDefaultColor(svtools::DOCCOLOR, 1);
765
766
0
            OUString aNewTheme;
767
0
            if (!pNewThemeArg) {
768
0
                ::Color aCurrentColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
769
770
0
                if (aCurrentColor == aDefLightColor) {
771
0
                    aNewTheme = OUString("Dark");
772
0
                } else {
773
0
                    aNewTheme = OUString("Light");
774
0
                }
775
0
            } else {
776
0
                aNewTheme = pNewThemeArg->GetValue();
777
0
            }
778
779
0
            svtools::ColorConfigValue aValue;
780
781
0
            if(aNewTheme == "Dark")
782
0
                aValue.nColor = aDefDarkColor;
783
0
            else
784
0
                aValue.nColor = aDefLightColor;
785
786
0
            aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue);
787
0
            break;
788
0
        }
789
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
790
0
        case SID_HELPINDEX:
791
0
        {
792
0
            Help* pHelp = Application::GetHelp();
793
0
            if ( pHelp )
794
0
            {
795
0
                pHelp->Start(u".uno:HelpIndex"_ustr, rReq.GetFrameWeld()); // show start page
796
0
                bDone = true;
797
0
            }
798
0
            break;
799
0
        }
800
801
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
802
0
        case SID_HELPTIPS:
803
0
        {
804
            // Evaluate Parameter
805
0
            const SfxBoolItem* pOnItem = rReq.GetArg(SID_HELPTIPS);
806
0
            bool bOn = pOnItem
807
0
                            ? pOnItem->GetValue()
808
0
                            : !Help::IsQuickHelpEnabled();
809
810
0
            if ( bOn )
811
0
                Help::EnableQuickHelp();
812
0
            else
813
0
                Help::DisableQuickHelp();
814
0
            auto xChanges = comphelper::ConfigurationChanges::create();
815
0
            officecfg::Office::Common::Help::Tip::set(bOn, xChanges);
816
0
            xChanges->commit();
817
0
            Invalidate(SID_HELPTIPS);
818
0
            bDone = true;
819
820
            // Record if possible
821
0
            if ( !rReq.IsAPI() )
822
0
                rReq.AppendItem( SfxBoolItem( SID_HELPTIPS, bOn) );
823
0
            break;
824
0
        }
825
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
826
0
        case SID_EXTENDEDHELP:
827
0
        {
828
0
            Help::StartExtHelp();
829
0
            break;
830
0
        }
831
0
        case SID_HELPBALLOONS:
832
0
        {
833
            // Evaluate Parameter
834
0
            const SfxBoolItem* pOnItem = rReq.GetArg(SID_HELPBALLOONS);
835
0
            bool bOn = pOnItem
836
0
                            ? pOnItem->GetValue()
837
0
                            : !Help::IsBalloonHelpEnabled();
838
839
0
            if ( bOn )
840
0
                Help::EnableBalloonHelp();
841
0
            else
842
0
                Help::DisableBalloonHelp();
843
0
            auto xChanges = comphelper::ConfigurationChanges::create();
844
0
            officecfg::Office::Common::Help::ExtendedTip::set(bOn, xChanges);
845
0
            xChanges->commit();
846
0
            Invalidate(SID_HELPBALLOONS);
847
0
            bDone = true;
848
849
            // Record if possible
850
0
            if ( !rReq.IsAPI() )
851
0
                rReq.AppendItem( SfxBoolItem( SID_HELPBALLOONS, bOn) );
852
0
            break;
853
0
        }
854
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
855
0
#if !ENABLE_WASM_STRIP_PINGUSER
856
0
        case SID_TIPOFTHEDAY:
857
0
        {
858
0
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
859
0
            ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTipOfTheDayDialog(rReq.GetFrameWeld()));
860
0
            pDlg->StartExecuteAsync(nullptr);
861
0
            bDone = true;
862
0
            break;
863
0
        }
864
0
#endif
865
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
866
0
        case SID_WIDGET_TEST_DIALOG:
867
0
        {
868
0
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
869
0
            VclPtr<VclAbstractDialog> pDlg(pFact->CreateWidgetTestDialog(rReq.GetFrameWeld()));
870
0
            pDlg->StartExecuteAsync([pDlg](sal_Int32 /*nResult*/){
871
0
                pDlg->disposeOnce();
872
0
            });
873
0
            bDone = true;
874
0
            break;
875
0
        }
876
877
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
878
0
        case SID_ABOUT:
879
0
        {
880
0
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
881
0
            ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateAboutDialog(rReq.GetFrameWeld()));
882
0
            pDlg->StartExecuteAsync(nullptr);
883
0
            bDone = true;
884
0
            break;
885
0
        }
886
887
0
        case SID_EXTENSION_MANAGER:
888
0
        {
889
0
            css::uno::Reference<css::awt::XWindow> xParent;
890
0
            if (weld::Window* pWindow = rReq.GetFrameWeld())
891
0
                xParent = pWindow->GetXWindow();
892
893
0
            Reference<ui::dialogs::XAsynchronousExecutableDialog> xDialog(
894
0
                css::deployment::ui::PackageManagerDialog::create(
895
0
                    comphelper::getProcessComponentContext(), xParent, OUString()));
896
0
            assert(xDialog.is());
897
0
            xDialog->startExecuteModal({});
898
0
            bDone = true;
899
0
            break;
900
0
        }
901
902
0
        case SID_TEMPLATE_MANAGER:
903
0
        {
904
0
            SfxTemplateManagerDlg aDialog(rReq.GetFrameWeld());
905
0
            aDialog.run();
906
0
            bDone = true;
907
0
            break;
908
0
        }
909
910
0
        case SID_TEMPLATE_ADDRESSBOOKSOURCE:
911
0
        {
912
0
            svt::AddressBookSourceDialog aDialog(rReq.GetFrameWeld(), ::comphelper::getProcessComponentContext());
913
0
            aDialog.run();
914
0
            bDone = true;
915
0
            break;
916
0
        }
917
918
#if HAVE_FEATURE_SCRIPTING
919
        case SID_BASICSTOP:
920
            StarBASIC::Stop();
921
            break;
922
923
        case SID_BASICBREAK :
924
            BasicDLL::BasicBreak();
925
            break;
926
#endif
927
928
0
        case SID_ZOOM_50_PERCENT:
929
0
        case SID_ZOOM_75_PERCENT:
930
0
        case SID_ZOOM_100_PERCENT:
931
0
        case SID_ZOOM_150_PERCENT:
932
0
        case SID_ZOOM_200_PERCENT:
933
0
        case SID_ZOOM_OPTIMAL:
934
0
        case SID_ZOOM_ENTIRE_PAGE:
935
0
        case SID_ZOOM_PAGE_WIDTH:
936
0
        {
937
0
            SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
938
0
            if (!pCurrentShell)
939
0
                return;
940
941
            // make sure aZoom is initialized with a proper value if SetType
942
            // doesn't work
943
0
            SvxZoomItem aZoom( SvxZoomType::PERCENT, 100 );
944
945
0
            switch (rReq.GetSlot())
946
0
            {
947
0
                case SID_ZOOM_50_PERCENT:
948
0
                    aZoom.SetValue(50);
949
0
                    break;
950
0
                case SID_ZOOM_75_PERCENT:
951
0
                    aZoom.SetValue(75);
952
0
                    break;
953
0
                case SID_ZOOM_100_PERCENT:
954
0
                    aZoom.SetValue(100);
955
0
                    break;
956
0
                case SID_ZOOM_150_PERCENT:
957
0
                    aZoom.SetValue(150);
958
0
                    break;
959
0
                case SID_ZOOM_200_PERCENT:
960
0
                    aZoom.SetValue(200);
961
0
                    break;
962
0
                case SID_ZOOM_OPTIMAL:
963
0
                    aZoom.SetType( SvxZoomType::OPTIMAL );
964
0
                    break;
965
0
                case SID_ZOOM_ENTIRE_PAGE:
966
0
                    aZoom.SetType( SvxZoomType::WHOLEPAGE );
967
0
                    break;
968
0
                case SID_ZOOM_PAGE_WIDTH:
969
0
                    aZoom.SetType( SvxZoomType::PAGEWIDTH );
970
0
                    break;
971
0
            }
972
973
0
            pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::ASYNCHRON, { &aZoom });
974
975
0
            break;
976
0
        }
977
0
        case SID_TOOLBAR_MODE:
978
0
        {
979
0
            const SfxStringItem* pModeName = rReq.GetArg<SfxStringItem>( SID_TOOLBAR_MODE );
980
981
0
            if ( !pModeName )
982
0
            {
983
0
                bDone = true;
984
0
                break;
985
0
            }
986
987
0
            OUString aNewName(pModeName->GetValue());
988
0
            const uno::Reference< uno::XComponentContext >& xContext =
989
0
                    ::comphelper::getProcessComponentContext();
990
991
            // Get information about current frame and module
992
0
            Reference<XFrame> xCurrentFrame;
993
0
            vcl::EnumContext::Application eCurrentApp = vcl::EnumContext::Application::NONE;
994
0
            OUString aCurrentMode;
995
996
0
            SfxViewFrame* pViewFrame = SfxViewFrame::Current();
997
0
            if (pViewFrame)
998
0
            {
999
0
                xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
1000
1001
0
                const Reference<frame::XModuleManager> xModuleManager  = frame::ModuleManager::create( xContext );
1002
0
                eCurrentApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xCurrentFrame ) );
1003
1004
0
                OUString aPath = "org.openoffice.Office.UI.ToolbarMode/Applications/" +
1005
0
                    lcl_getAppName( eCurrentApp );
1006
1007
0
                const utl::OConfigurationTreeRoot aAppNode(
1008
0
                                                    xContext,
1009
0
                                                    aPath,
1010
0
                                                    true);
1011
0
                if ( !aAppNode.isValid() )
1012
0
                {
1013
0
                    bDone = true;
1014
0
                    break;
1015
0
                }
1016
1017
0
                aCurrentMode = comphelper::getString( aAppNode.getNodeValue( u"Active"_ustr ) );
1018
1019
0
                if ( !comphelper::LibreOfficeKit::isActive() && aCurrentMode == aNewName )
1020
0
                {
1021
0
                    bDone = true;
1022
0
                    break;
1023
0
                }
1024
1025
                // Save new toolbar mode for a current module
1026
0
                aAppNode.setNodeValue( u"Active"_ustr, Any( aNewName ) );
1027
0
                aAppNode.commit();
1028
0
            }
1029
1030
            // Apply settings for all frames
1031
0
            pViewFrame = SfxViewFrame::GetFirst();
1032
0
            while( pViewFrame )
1033
0
            {
1034
                // in LOK case we want to apply changes only to the current view
1035
0
                if (comphelper::LibreOfficeKit::isActive() &&
1036
0
                    pViewFrame != &SfxViewShell::Current()->GetViewFrame())
1037
0
                {
1038
0
                    pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
1039
0
                    continue;
1040
0
                }
1041
1042
0
                Reference<XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
1043
1044
                // We want to change mode only for a current app module, ignore other apps
1045
0
                const Reference<frame::XModuleManager> xModuleManager  = frame::ModuleManager::create( xContext );
1046
0
                vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) );
1047
0
                if ( eApp != eCurrentApp )
1048
0
                {
1049
0
                    pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
1050
0
                    continue;
1051
0
                }
1052
1053
0
                Reference<css::beans::XPropertySet> xPropSet( xFrame, UNO_QUERY );
1054
0
                Reference<css::frame::XLayoutManager> xLayoutManager;
1055
0
                if ( xPropSet.is() )
1056
0
                {
1057
0
                    try
1058
0
                    {
1059
0
                        Any aValue = xPropSet->getPropertyValue( u"LayoutManager"_ustr );
1060
0
                        aValue >>= xLayoutManager;
1061
0
                    }
1062
0
                    catch ( const css::uno::RuntimeException& )
1063
0
                    {
1064
0
                        throw;
1065
0
                    }
1066
0
                    catch ( css::uno::Exception& )
1067
0
                    {
1068
0
                    }
1069
0
                }
1070
1071
0
                if ( xLayoutManager.is() )
1072
0
                {
1073
0
                    css::uno::Sequence<OUString> aMandatoryToolbars;
1074
0
                    css::uno::Sequence<OUString> aUserToolbars;
1075
0
                    std::vector<OUString> aBackupList;
1076
0
                    OUString aSidebarMode;
1077
1078
0
                    OUString aPath = "org.openoffice.Office.UI.ToolbarMode/Applications/" +
1079
0
                        lcl_getAppName( eApp ) +
1080
0
                        "/Modes";
1081
1082
                    // Read mode settings
1083
0
                    const utl::OConfigurationTreeRoot aModesNode(
1084
0
                                            xContext,
1085
0
                                            aPath,
1086
0
                                            true);
1087
0
                    if ( !aModesNode.isValid() )
1088
0
                    {
1089
0
                        bDone = true;
1090
0
                        break;
1091
0
                    }
1092
1093
0
                    const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() );
1094
1095
0
                    for ( const auto& rModeNodeName : aModeNodeNames )
1096
0
                    {
1097
0
                        const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
1098
0
                        if ( !aModeNode.isValid() )
1099
0
                            continue;
1100
1101
0
                        OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( u"CommandArg"_ustr ) );
1102
1103
0
                        if ( aCommandArg == aNewName )
1104
0
                        {
1105
0
                            aMandatoryToolbars = aModeNode.getNodeValue( u"Toolbars"_ustr ).get< uno::Sequence<OUString> >();
1106
0
                            aUserToolbars = aModeNode.getNodeValue( u"UserToolbars"_ustr ).get< uno::Sequence<OUString> >();
1107
0
                            aSidebarMode = comphelper::getString( aModeNode.getNodeValue( u"Sidebar"_ustr ) );
1108
0
                            break;
1109
0
                        }
1110
0
                    }
1111
1112
                    // Backup visible toolbar list and hide all toolbars
1113
0
                    const Sequence<Reference<XUIElement>> aUIElements = xLayoutManager->getElements();
1114
0
                    for ( const Reference< XUIElement >& xUIElement : aUIElements )
1115
0
                    {
1116
0
                        Reference< XPropertySet > xPropertySet( xUIElement, UNO_QUERY );
1117
0
                        if ( xPropertySet.is() && xUIElement.is() )
1118
0
                        {
1119
0
                            try
1120
0
                            {
1121
0
                                OUString aResName;
1122
0
                                sal_Int16 nType( -1 );
1123
0
                                xPropertySet->getPropertyValue( u"Type"_ustr ) >>= nType;
1124
0
                                xPropertySet->getPropertyValue( u"ResourceURL"_ustr ) >>= aResName;
1125
1126
0
                                if (( nType == css::ui::UIElementType::TOOLBAR ) &&
1127
0
                                    !aResName.isEmpty() )
1128
0
                                {
1129
0
                                    if ( xLayoutManager->isElementVisible( aResName ) )
1130
0
                                    {
1131
0
                                        aBackupList.push_back( aResName );
1132
0
                                    }
1133
0
                                    xLayoutManager->hideElement( aResName );
1134
0
                                }
1135
0
                            }
1136
0
                            catch ( const Exception& )
1137
0
                            {
1138
0
                            }
1139
0
                        }
1140
0
                    }
1141
1142
                    // Show/Hide the Notebookbar
1143
0
                    const SfxStringItem pItem(SID_NOTEBOOKBAR, aNewName);
1144
0
                    pViewFrame->GetDispatcher()->ExecuteList(SID_NOTEBOOKBAR, SfxCallMode::SYNCHRON, {&pItem});
1145
0
                    SfxPoolItemHolder aNbItem;
1146
0
                    pViewFrame->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, aNbItem);
1147
1148
                    // Show toolbars
1149
0
                    for (const OUString& rName : aMandatoryToolbars)
1150
0
                    {
1151
0
                        xLayoutManager->createElement( rName );
1152
0
                        xLayoutManager->showElement( rName );
1153
0
                    }
1154
1155
0
                    for (const OUString& rName : aUserToolbars)
1156
0
                    {
1157
0
                        xLayoutManager->createElement( rName );
1158
0
                        xLayoutManager->showElement( rName );
1159
0
                    }
1160
1161
                    // Sidebar
1162
0
                    pViewFrame->ShowChildWindow( SID_SIDEBAR );
1163
1164
0
                    if (comphelper::LibreOfficeKit::isActive())
1165
0
                        aSidebarMode = "Opened";
1166
1167
0
                    sfx2::sidebar::SidebarController* pSidebar =
1168
0
                            sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame );
1169
0
                    if ( pSidebar )
1170
0
                    {
1171
0
                        if ( aSidebarMode == "Arrow" )
1172
0
                        {
1173
0
                            pSidebar->FadeOut();
1174
0
                        }
1175
0
                        else if ( aSidebarMode == "Tabs" )
1176
0
                        {
1177
0
                            pSidebar->FadeIn();
1178
0
                            pSidebar->RequestOpenDeck();
1179
0
                            pSidebar->RequestCloseDeck();
1180
0
                        }
1181
0
                        else if ( aSidebarMode == "Opened" )
1182
0
                        {
1183
0
                            pSidebar->FadeIn();
1184
0
                            pSidebar->RequestOpenDeck();
1185
0
                        }
1186
0
                    }
1187
1188
                    // Save settings
1189
0
                    if ( pViewFrame == SfxViewFrame::Current() )
1190
0
                    {
1191
0
                        css::uno::Sequence<OUString> aBackup( comphelper::containerToSequence(aBackupList) );
1192
1193
0
                        for ( const auto& rModeNodeName : aModeNodeNames )
1194
0
                        {
1195
0
                            const utl::OConfigurationNode aModeNode( aModesNode.openNode( rModeNodeName ) );
1196
0
                            if ( !aModeNode.isValid() )
1197
0
                                continue;
1198
1199
0
                            OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( u"CommandArg"_ustr ) );
1200
1201
0
                            if ( aCommandArg == aCurrentMode )
1202
0
                            {
1203
0
                                aModeNode.setNodeValue( u"UserToolbars"_ustr, Any( aBackup ) );
1204
0
                                break;
1205
0
                            }
1206
0
                        }
1207
0
                        aModesNode.commit();
1208
0
                    }
1209
0
                }
1210
1211
0
                pViewFrame = SfxViewFrame::GetNext(*pViewFrame);
1212
0
            }
1213
1214
0
            bDone = true;
1215
0
            break;
1216
0
        }
1217
0
        case SID_UI_PICKER:
1218
0
        {
1219
0
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1220
0
            ScopedVclPtr<VclAbstractDialog> pDlg(
1221
0
                pFact->CreateUIPickerDialog(rReq.GetFrameWeld()));
1222
0
            pDlg->Execute();
1223
0
            bDone = true;
1224
0
            break;
1225
0
        }
1226
0
        case SID_AVAILABLE_TOOLBARS:
1227
0
        {
1228
0
            const SfxStringItem* pToolbarName = rReq.GetArg<SfxStringItem>(SID_AVAILABLE_TOOLBARS);
1229
1230
0
            if ( pToolbarName )
1231
0
            {
1232
0
                Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
1233
0
                Reference< XFrame > xFrame = xDesktop->getActiveFrame();
1234
1235
0
                Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
1236
0
                Reference< css::frame::XLayoutManager > xLayoutManager;
1237
0
                if ( xPropSet.is() )
1238
0
                {
1239
0
                    try
1240
0
                    {
1241
0
                        Any aValue = xPropSet->getPropertyValue(u"LayoutManager"_ustr);
1242
0
                        aValue >>= xLayoutManager;
1243
0
                    }
1244
0
                    catch ( const css::uno::RuntimeException& )
1245
0
                    {
1246
0
                        throw;
1247
0
                    }
1248
0
                    catch ( css::uno::Exception& )
1249
0
                    {
1250
0
                    }
1251
0
                }
1252
1253
0
                if ( xLayoutManager.is() )
1254
0
                {
1255
0
                    OUString aToolbarName = "private:resource/toolbar/" +
1256
0
                        pToolbarName->GetValue();
1257
1258
                    // Evaluate Parameter
1259
0
                    bool bShow( !xLayoutManager->isElementVisible( aToolbarName ));
1260
1261
0
                    if ( bShow )
1262
0
                    {
1263
0
                        xLayoutManager->createElement( aToolbarName );
1264
0
                        xLayoutManager->showElement( aToolbarName );
1265
0
                    }
1266
0
                    else
1267
0
                        xLayoutManager->hideElement( aToolbarName );
1268
0
                }
1269
0
            }
1270
1271
0
            bDone = true;
1272
0
            break;
1273
0
        }
1274
0
        case SID_MENUBAR:
1275
0
        {
1276
0
            sfx2::SfxNotebookBar::ToggleMenubar();
1277
0
            bDone = true;
1278
0
            break;
1279
0
        }
1280
0
        case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW:
1281
0
        {
1282
0
            SfxViewShell* pViewShell = SfxViewShell::Current();
1283
0
            SfxViewFrame& rViewFrame = pViewShell->GetViewFrame();
1284
0
            auto nID = rReq.GetSlot();
1285
0
            rViewFrame.ToggleChildWindow(nID);
1286
1287
0
            bDone = true;
1288
0
            break;
1289
0
        }
1290
0
        case SID_INSPECT_SELECTED_OBJECT:
1291
0
        {
1292
0
            SfxViewShell* pViewShell = SfxViewShell::Current();
1293
0
            SfxViewFrame& rViewFrame = pViewShell->GetViewFrame();
1294
1295
0
            rViewFrame.ShowChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW, true);
1296
1297
0
            SfxChildWindow* pChild = rViewFrame.GetChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW);
1298
0
            if (!pChild)
1299
0
                return;
1300
1301
0
            auto pDockingWin = dynamic_cast<DevelopmentToolDockingWindow*>(pChild->GetWindow());
1302
0
            if (pDockingWin)
1303
0
            {
1304
0
                pDockingWin->changeToCurrentSelection();
1305
0
            }
1306
1307
0
            bDone = true;
1308
0
            break;
1309
0
        }
1310
0
        case SID_SAFE_MODE:
1311
0
        {
1312
0
            SafeModeQueryDialog aDialog(rReq.GetFrameWeld());
1313
0
            aDialog.run();
1314
0
            break;
1315
0
        }
1316
0
        default:
1317
0
            break;
1318
0
    }
1319
1320
0
    if ( bDone )
1321
0
        rReq.Done();
1322
0
}
1323
1324
void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
1325
0
{
1326
0
    const WhichRangesContainer & pRanges = rSet.GetRanges();
1327
0
    DBG_ASSERT(!pRanges.empty(), "Set without range");
1328
0
    for ( auto const & pRange : pRanges )
1329
0
    {
1330
0
        for(sal_uInt16 nWhich = pRange.first; nWhich <= pRange.second; ++nWhich)
1331
0
        {
1332
0
            switch(nWhich)
1333
0
            {
1334
0
                case SID_TEMPLATE_ADDRESSBOOKSOURCE:
1335
0
                    if (!SvtModuleOptions().IsDataBaseInstalled())
1336
0
                        rSet.Put(SfxVisibilityItem(nWhich, false));
1337
0
                    break;
1338
0
                case SID_QUITAPP:
1339
0
                {
1340
0
                    if (pImpl->nDocModalMode || pImpl->bClosingDocs)
1341
0
                        rSet.DisableItem(nWhich);
1342
0
                    else
1343
0
                        rSet.Put(SfxStringItem(nWhich, SfxResId(STR_QUITAPP)));
1344
0
                    break;
1345
0
                }
1346
1347
0
                case SID_CONFIG:
1348
0
                case SID_TOOLBOXOPTIONS:
1349
0
                case SID_CONFIGSTATUSBAR:
1350
0
                case SID_CONFIGMENU:
1351
0
                case SID_CONFIGACCEL:
1352
0
                case SID_CONFIGEVENT:
1353
0
                {
1354
0
                    if( officecfg::Office::Common::Misc::DisableUICustomization::get() )
1355
0
                        rSet.DisableItem(nWhich);
1356
0
                    break;
1357
0
                }
1358
1359
#if HAVE_FEATURE_SCRIPTING
1360
                case SID_BASICSTOP:
1361
                    if ( !StarBASIC::IsRunning() )
1362
                        rSet.DisableItem(nWhich);
1363
                    break;
1364
#endif
1365
1366
0
                case FN_CHANGE_THEME:
1367
0
                {
1368
0
                    const bool bIsDarkMode
1369
0
                        = MiscSettings::GetAppColorMode() == AppearanceMode::DARK
1370
0
                          || (MiscSettings::GetAppColorMode() == AppearanceMode::AUTO
1371
0
                              && MiscSettings::GetUseDarkMode());
1372
0
                    rSet.Put(SfxBoolItem(FN_CHANGE_THEME, bIsDarkMode));
1373
0
                    break;
1374
0
                }
1375
0
                case SID_HELPTIPS:
1376
0
                {
1377
0
                    rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );
1378
0
                }
1379
0
                break;
1380
0
                case SID_HELPBALLOONS:
1381
0
                {
1382
0
                    rSet.Put( SfxBoolItem( SID_HELPBALLOONS, Help::IsBalloonHelpEnabled() ) );
1383
0
                }
1384
0
                break;
1385
1386
0
                case SID_EXTENDEDHELP:
1387
0
                {
1388
0
                }
1389
0
                break;
1390
1391
0
                case SID_CLOSEDOCS:
1392
0
                {
1393
0
                    if ( pImpl->nDocModalMode || pImpl->bInQuit )
1394
0
                    {
1395
0
                        rSet.DisableItem(nWhich);
1396
0
                        return;
1397
0
                    }
1398
0
                    Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1399
0
                    Reference< XIndexAccess > xTasks = xDesktop->getFrames();
1400
0
                    if ( !xTasks.is() || !xTasks->getCount() )
1401
0
                        rSet.DisableItem(nWhich);
1402
0
                    break;
1403
0
                }
1404
1405
0
                case SID_SAVEDOCS:
1406
0
                {
1407
0
                    bool bModified = false;
1408
0
                    for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
1409
0
                          pObjSh;
1410
0
                          pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
1411
0
                    {
1412
0
                        if ( pObjSh->IsModified() && !pObjSh->isSaveLocked() )
1413
0
                        {
1414
0
                            bModified = true;
1415
0
                            break;
1416
0
                        }
1417
0
                    }
1418
1419
0
                    if ( !bModified )
1420
0
                        rSet.DisableItem( nWhich );
1421
0
                    break;
1422
0
                }
1423
1424
0
                case SID_TEMPLATE_MANAGER:
1425
0
                    {
1426
0
                        if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1427
0
                        {
1428
0
                           rSet.DisableItem( nWhich );
1429
0
                           rSet.Put( SfxVisibilityItem( nWhich, false ) );
1430
0
                        }
1431
0
                    }
1432
0
                    break;
1433
1434
0
                case SID_ZOOM_50_PERCENT:
1435
0
                case SID_ZOOM_75_PERCENT:
1436
0
                case SID_ZOOM_100_PERCENT:
1437
0
                case SID_ZOOM_150_PERCENT:
1438
0
                case SID_ZOOM_200_PERCENT:
1439
0
                case SID_ZOOM_OPTIMAL:
1440
0
                case SID_ZOOM_ENTIRE_PAGE:
1441
0
                case SID_ZOOM_PAGE_WIDTH:
1442
0
                    {
1443
0
                        SfxObjectShell* pCurrentShell(SfxObjectShell::Current());
1444
1445
0
                        SfxPoolItemHolder aResult;
1446
0
                        const SfxItemState aState(pCurrentShell ?
1447
0
                            pCurrentShell->GetDispatcher()->QueryState(SID_ATTR_ZOOM, aResult) : SfxItemState::DISABLED);
1448
0
                        if ( aState == SfxItemState::DISABLED )
1449
0
                            rSet.DisableItem( nWhich );
1450
0
                    }
1451
0
                    break;
1452
1453
0
                case SID_MENUBAR:
1454
0
                {
1455
0
                    Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
1456
0
                    Reference< XFrame > xFrame = xDesktop->getActiveFrame();
1457
1458
0
                    Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
1459
0
                    Reference< css::frame::XLayoutManager > xLayoutManager;
1460
0
                    if ( xPropSet.is() )
1461
0
                    {
1462
0
                        try
1463
0
                        {
1464
0
                            Any aValue = xPropSet->getPropertyValue(u"LayoutManager"_ustr);
1465
0
                            aValue >>= xLayoutManager;
1466
0
                        }
1467
0
                        catch ( const css::uno::RuntimeException& )
1468
0
                        {
1469
0
                            throw;
1470
0
                        }
1471
0
                        catch ( css::uno::Exception& )
1472
0
                        {
1473
0
                        }
1474
0
                    }
1475
1476
0
                    if ( xLayoutManager.is() )
1477
0
                    {
1478
0
                        const bool bState
1479
0
                            = xLayoutManager->getElement(u"private:resource/menubar/menubar"_ustr).is()
1480
0
                              && xLayoutManager->isElementVisible(
1481
0
                                     u"private:resource/menubar/menubar"_ustr);
1482
1483
0
                        SfxBoolItem aItem( SID_MENUBAR, bState );
1484
0
                        rSet.Put( aItem );
1485
0
                    }
1486
0
                    break;
1487
0
                }
1488
0
                case SID_SAFE_MODE:
1489
0
                {
1490
                    // no restart in troubleshoot mode when already in it
1491
0
                    if ( Application::IsSafeModeEnabled() )
1492
0
                       rSet.DisableItem( SID_SAFE_MODE );
1493
0
                    break;
1494
0
                }
1495
0
                case SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW:
1496
0
                {
1497
0
                    bool bSuccess = false;
1498
0
                    auto* pViewShell = SfxViewShell::Current();
1499
0
                    if (pViewShell)
1500
0
                    {
1501
0
                        auto& rViewFrame = pViewShell->GetViewFrame();
1502
0
                        if (rViewFrame.KnowsChildWindow(nWhich))
1503
0
                        {
1504
0
                            rSet.Put(SfxBoolItem(nWhich, rViewFrame.HasChildWindow(nWhich)));
1505
0
                            bSuccess = true;
1506
0
                        }
1507
0
                    }
1508
1509
0
                    if (!bSuccess)
1510
0
                        rSet.DisableItem(nWhich);
1511
0
                }
1512
0
                break;
1513
0
                case SID_INSPECT_SELECTED_OBJECT:
1514
0
                {
1515
0
                    bool bSuccess = false;
1516
0
                    auto* pViewShell = SfxViewShell::Current();
1517
0
                    if (pViewShell)
1518
0
                    {
1519
0
                        auto& rViewFrame = pViewShell->GetViewFrame();
1520
0
                        if (rViewFrame.KnowsChildWindow(SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW))
1521
0
                        {
1522
0
                            bSuccess = true;
1523
0
                        }
1524
0
                    }
1525
0
                    if (!bSuccess)
1526
0
                        rSet.DisableItem(nWhich);
1527
0
                }
1528
0
                break;
1529
0
                default:
1530
0
                    break;
1531
0
            }
1532
0
        }
1533
0
    }
1534
0
}
1535
1536
#if HAVE_FEATURE_SCRIPTING
1537
1538
#ifndef DISABLE_DYNLOADING
1539
1540
typedef rtl_uString* (*basicide_choose_macro)(void*, void*, void*, sal_Bool);
1541
1542
#else
1543
1544
extern "C" rtl_uString* basicide_choose_macro(void*, void*, void*, sal_Bool);
1545
1546
#endif
1547
1548
static OUString ChooseMacro(weld::Window* pParent, const Reference<XModel>& rxLimitToDocument, const Reference<XFrame>& xDocFrame, bool bChooseOnly)
1549
{
1550
#ifndef DISABLE_DYNLOADING
1551
    basicide_choose_macro pSymbol = reinterpret_cast<basicide_choose_macro>(sfx2::getBasctlFunction("basicide_choose_macro"));
1552
#else
1553
#define pSymbol basicide_choose_macro
1554
#endif
1555
1556
    // call basicide_choose_macro in basctl
1557
    rtl_uString* pScriptURL = pSymbol(pParent, rxLimitToDocument.get(), xDocFrame.get(), bChooseOnly);
1558
    OUString aScriptURL( pScriptURL );
1559
    rtl_uString_release( pScriptURL );
1560
    return aScriptURL;
1561
1562
#ifdef DISABLE_DYNLOADING
1563
#undef pSymbol
1564
#endif
1565
}
1566
1567
#endif
1568
1569
namespace
1570
{
1571
#if HAVE_FEATURE_SCRIPTING
1572
    weld::Window* lcl_getDialogParent(const Reference<XFrame>& rxFrame)
1573
    {
1574
        Reference<awt::XWindow> xContainerWindow;
1575
        if (rxFrame.is())
1576
            xContainerWindow = rxFrame->getContainerWindow();
1577
        return Application::GetFrameWeld(xContainerWindow);
1578
    }
1579
1580
    SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell const * i_pBasicIDE )
1581
    {
1582
        SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
1583
        while ( pView )
1584
        {
1585
            if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == "com.sun.star.script.BasicIDE" )
1586
                break;
1587
            pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
1588
        }
1589
        return pView;
1590
    }
1591
    Reference< XFrame > lcl_findStartModuleFrame( const Reference<XComponentContext> & rxContext )
1592
    {
1593
        try
1594
        {
1595
            Reference < XDesktop2 > xDesktop = Desktop::create( rxContext );
1596
            Reference < XIndexAccess > xContainer( xDesktop->getFrames(), UNO_QUERY_THROW );
1597
1598
            Reference< XModuleManager2 > xCheck = ModuleManager::create(rxContext);
1599
1600
            sal_Int32 nCount = xContainer->getCount();
1601
            for ( sal_Int32 i=0; i<nCount; ++i )
1602
            {
1603
                try
1604
                {
1605
                    Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
1606
                    OUString sModule = xCheck->identify( xFrame );
1607
                    if ( sModule == "com.sun.star.frame.StartModule" )
1608
                        return xFrame;
1609
                }
1610
                catch( const UnknownModuleException& )
1611
                {
1612
                    // silence
1613
                }
1614
                catch(const Exception&)
1615
                {
1616
                    // re-throw, caught below
1617
                    throw;
1618
                }
1619
            }
1620
        }
1621
        catch( const Exception& )
1622
        {
1623
               DBG_UNHANDLED_EXCEPTION("sfx.appl");
1624
        }
1625
        return nullptr;
1626
    }
1627
    void lcl_callXScript( const Reference < XFrame >& rxFrame,
1628
                          const Reference < css::uno::XInterface >& rxScriptContext,
1629
                          const OUString& rScriptURL )
1630
    {
1631
        Sequence< Any > args;
1632
        Sequence< sal_Int16 > outIndex;
1633
        Sequence< Any > outArgs;
1634
        Any ret;
1635
1636
        if (SfxObjectShell::CallXScript( rxScriptContext, rScriptURL, args,
1637
                                         ret, outIndex, outArgs ) == ERRCODE_IO_ACCESSDENIED)
1638
        {
1639
            if (weld::Window* pParent = lcl_getDialogParent(rxFrame))
1640
            {
1641
                std::unique_ptr<weld::MessageDialog> xBox(
1642
                    Application::CreateMessageDialog(pParent, VclMessageType::Warning,
1643
                                                     VclButtonsType::Ok,
1644
                                                     SfxResId(STR_CANNOTRUNMACRO)));
1645
                xBox->run();
1646
            }
1647
        }
1648
    }
1649
#endif // HAVE_FEATURE_SCRIPTING
1650
}
1651
1652
void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
1653
0
{
1654
0
    switch ( rReq.GetSlot() )
1655
0
    {
1656
0
        case SID_OPTIONS_TREEDIALOG:
1657
0
        {
1658
0
            OUString sPageURL;
1659
0
            const SfxStringItem* pURLItem = rReq.GetArg(SID_OPTIONS_PAGEURL);
1660
0
            if ( pURLItem )
1661
0
                sPageURL = pURLItem->GetValue();
1662
1663
0
            sal_uInt16 nPageID = 0;
1664
0
            const SfxUInt16Item* pIDItem = rReq.GetArg(SID_OPTIONS_PAGEID);
1665
0
            if (pIDItem)
1666
0
                nPageID = pIDItem->GetValue();
1667
1668
0
            Reference <XFrame> xFrame(GetRequestFrame(rReq));
1669
0
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1670
0
            VclPtr<VclAbstractDialog> pDlg =
1671
0
                pFact->CreateFrameDialog(rReq.GetFrameWeld(), xFrame, rReq.GetSlot(), nPageID, sPageURL);
1672
0
            short nRet = pDlg->Execute();
1673
0
            pDlg.disposeAndClear();
1674
0
            SfxViewFrame* pView = SfxViewFrame::GetFirst();
1675
0
            bool bDisableActiveContent
1676
0
                    = officecfg::Office::Common::Security::Scripting::DisableActiveContent::get();
1677
1678
0
            while ( pView )
1679
0
            {
1680
0
                if (nRet == RET_OK)
1681
0
                {
1682
0
                    SfxObjectShell* pObjSh = pView->GetObjectShell();
1683
0
                    if (pObjSh)
1684
0
                    {
1685
0
                        pObjSh->SetConfigOptionsChecked(false);
1686
1687
                        // when active content is disabled via options dialog,
1688
                        // disable all current active embedded objects
1689
0
                        if (bDisableActiveContent)
1690
0
                            lcl_disableActiveEmbeddedObjects(pObjSh);
1691
0
                    }
1692
0
                }
1693
0
                pView->GetBindings().InvalidateAll(false);
1694
0
                pView = SfxViewFrame::GetNext( *pView );
1695
0
            }
1696
0
            break;
1697
0
        }
1698
1699
0
        case SID_OPTIONS_SECURITY:
1700
0
        {
1701
0
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1702
0
            VclPtr<AbstractSecurityOptionsDialog> pDlg =
1703
0
                pFact->CreateSvxSecurityOptionsDialog(rReq.GetFrameWeld());
1704
1705
0
            if (pDlg->Execute() == RET_OK) {
1706
0
                pDlg->SetSecurityOptions();
1707
0
            }
1708
1709
0
            pDlg.disposeAndClear();
1710
0
            break;
1711
0
        }
1712
1713
0
        case SID_ADDITIONS_DIALOG:
1714
0
        {
1715
0
            OUString sAdditionsTag = u""_ustr;
1716
1717
0
            const SfxStringItem* pStringArg = rReq.GetArg(FN_PARAM_ADDITIONS_TAG);
1718
0
            if (pStringArg)
1719
0
                sAdditionsTag = pStringArg->GetValue();
1720
1721
0
            AdditionsDialogHelper::RunAdditionsDialog(rReq.GetFrameWeld(), sAdditionsTag);
1722
0
            break;
1723
0
        }
1724
1725
0
        case SID_MORE_DICTIONARIES:
1726
0
        {
1727
0
            AdditionsDialogHelper::RunAdditionsDialog(rReq.GetFrameWeld(), u"Dictionary"_ustr);
1728
0
            break;
1729
0
        }
1730
#if HAVE_FEATURE_SCRIPTING
1731
        case SID_BASICIDE_APPEAR:
1732
        {
1733
            SfxViewFrame* pView = lcl_getBasicIDEViewFrame( nullptr );
1734
            if ( !pView )
1735
            {
1736
                SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( u"com.sun.star.script.BasicIDE"_ustr );
1737
                pBasicIDE->DoInitNew();
1738
                pBasicIDE->SetModified( false );
1739
                try
1740
                {
1741
                    // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
1742
                    // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
1743
                    // does not really play nice with the framework's concept. For instance, it is a "singleton document",
1744
                    // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
1745
                    // So, since we know that our frame loader can handle it, we skip the generic framework loader
1746
                    // mechanism, and the type detection (which doesn't know about the Basic IDE).
1747
                    const Reference< XComponentContext >& xContext( ::comphelper::getProcessComponentContext() );
1748
                    Reference< XSynchronousFrameLoader > xLoader(
1749
                        xContext->getServiceManager()->createInstanceWithContext(u"com.sun.star.comp.office.FrameLoader"_ustr, xContext),
1750
                        UNO_QUERY_THROW );
1751
                    ::comphelper::NamedValueCollection aLoadArgs;
1752
                    aLoadArgs.put( u"Model"_ustr, pBasicIDE->GetModel() );
1753
                    aLoadArgs.put( u"URL"_ustr, u"private:factory/sbasic"_ustr );
1754
1755
                    Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( xContext ) );
1756
                    if ( !xTargetFrame.is() )
1757
                        xTargetFrame = SfxFrame::CreateBlankFrame();
1758
                    ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
1759
1760
                    xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
1761
                }
1762
                catch( const Exception& )
1763
                {
1764
                    DBG_UNHANDLED_EXCEPTION("sfx.appl");
1765
                }
1766
1767
                pView = lcl_getBasicIDEViewFrame( pBasicIDE );
1768
                if ( pView )
1769
                    pView->SetName( u"BASIC:1"_ustr );
1770
            }
1771
1772
            if ( pView )
1773
                pView->GetFrame().Appear();
1774
1775
            const SfxItemSet* pArgs = rReq.GetArgs();
1776
            if ( pArgs && pView )
1777
            {
1778
                SfxViewShell* pViewShell = pView->GetViewShell();
1779
                SfxObjectShell* pObjShell = pView->GetObjectShell();
1780
                if ( pViewShell && pObjShell )
1781
                {
1782
                    SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SfxCallMode::SYNCHRON, pObjShell->GetPool() );
1783
                    aReq.SetArgs( *pArgs );
1784
                    pViewShell->ExecuteSlot( aReq );
1785
                }
1786
            }
1787
1788
            rReq.Done();
1789
        }
1790
        break;
1791
1792
        case SID_BASICCHOOSER:
1793
        {
1794
            const SfxItemSet* pArgs = rReq.GetArgs();
1795
            const SfxBoolItem* pItem;
1796
            bool bChooseOnly = false;
1797
            Reference< XModel > xLimitToModel;
1798
            if(pArgs && (pItem = pArgs->GetItemIfSet(SID_RECORDMACRO, false)) )
1799
            {
1800
                bool bRecord = pItem->GetValue();
1801
                if ( bRecord )
1802
                {
1803
                    // !Hack
1804
                    bChooseOnly = false;
1805
                    SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
1806
                    OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
1807
                    if ( pCurrentShell )
1808
                        xLimitToModel = pCurrentShell->GetModel();
1809
                }
1810
            }
1811
1812
            Reference <XFrame> xFrame(GetRequestFrame(rReq));
1813
            rReq.SetReturnValue(SfxStringItem(rReq.GetSlot(), ChooseMacro(rReq.GetFrameWeld(), xLimitToModel, xFrame, bChooseOnly)));
1814
            rReq.Done();
1815
        }
1816
        break;
1817
1818
        case SID_MACROORGANIZER:
1819
        {
1820
            SAL_INFO("sfx.appl", "handling SID_MACROORGANIZER");
1821
            const SfxItemSet* pArgs = rReq.GetArgs();
1822
            sal_Int16 nTabId = 0;
1823
            Reference <XFrame> xFrame;
1824
            if (pArgs)
1825
            {
1826
                if (const SfxUInt16Item* pItem = pArgs->GetItemIfSet(SID_MACROORGANIZER, false))
1827
                    nTabId = pItem->GetValue();
1828
                if (const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_2))
1829
                {
1830
                    // if set then default to showing the macros of the document associated
1831
                    // with this frame
1832
                    if (pItem->GetValue())
1833
                        xFrame = GetRequestFrame(rReq);
1834
                }
1835
            }
1836
            SfxApplication::MacroOrganizer(rReq.GetFrameWeld(), xFrame, nTabId);
1837
            rReq.Done();
1838
        }
1839
        break;
1840
1841
        case SID_RUNMACRO:
1842
        {
1843
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1844
            SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1845
1846
            Reference <XFrame> xFrame(GetRequestFrame(rReq));
1847
            if ( !xFrame.is() )
1848
            {
1849
                if (const SfxViewFrame* pViewFrame = SfxViewFrame::Current())
1850
                    xFrame = pViewFrame->GetFrame().GetFrameInterface();
1851
            }
1852
1853
            do  // artificial loop for flow control
1854
            {
1855
                VclPtr<AbstractScriptSelectorDialog> pDlg(pFact->CreateScriptSelectorDialog(lcl_getDialogParent(xFrame), xFrame));
1856
                OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
1857
                if ( !pDlg )
1858
                    break;
1859
                pDlg->SetRunLabel();
1860
1861
                pDlg->StartExecuteAsync([pDlg, xFrame](sal_Int32 nDialogResult) {
1862
                    if ( !nDialogResult )
1863
                    {
1864
                        pDlg->disposeOnce();
1865
                        return;
1866
                    }
1867
1868
                    lcl_callXScript(xFrame, pDlg->GetScriptModel(), pDlg->GetScriptURL());
1869
                    pDlg->disposeOnce();
1870
                });
1871
            }
1872
            while ( false );
1873
            rReq.Done();
1874
        }
1875
        break;
1876
1877
        case SID_SCRIPTORGANIZER:
1878
        {
1879
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1880
            SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: case ScriptOrg");
1881
            const SfxItemSet* pArgs = rReq.GetArgs();
1882
            const SfxScriptOrganizerItem* pItem;
1883
            OUString aLanguage;
1884
            if(pArgs && (pItem = pArgs->GetItemIfSet(SID_SCRIPTORGANIZER, false) ))
1885
            {
1886
                aLanguage = pItem->getLanguage();
1887
            }
1888
1889
            OUString aLang( aLanguage );
1890
            SAL_INFO("sfx.appl", "SfxApplication::OfaExec_Impl: about to create dialog for: " << aLang);
1891
            ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSvxScriptOrgDialog(rReq.GetFrameWeld(), aLanguage));
1892
            if( pDlg )
1893
            {
1894
                pDlg->Execute();
1895
            }
1896
            else
1897
            {
1898
                SAL_WARN("sfx.appl", "no dialog!!!");
1899
            }
1900
            rReq.Done();
1901
        }
1902
        break;
1903
1904
        case SID_MACROMANAGER:
1905
        {
1906
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1907
1908
            Reference<XFrame> xFrame(GetRequestFrame(rReq));
1909
            if (!xFrame.is())
1910
            {
1911
                if (const SfxViewFrame* pViewFrame = SfxViewFrame::Current())
1912
                    xFrame = pViewFrame->GetFrame().GetFrameInterface();
1913
            }
1914
1915
            VclPtr<AbstractMacroManagerDialog> pDlg(
1916
                pFact->CreateMacroManagerDialog(lcl_getDialogParent(xFrame), xFrame));
1917
            OSL_ENSURE(pDlg, "SfxApplication::OfaExec_Impl(SID_MACROMANAGER): no dialog!");
1918
            if (pDlg)
1919
            {
1920
                pDlg->StartExecuteAsync(
1921
                    [pDlg, xFrame](sal_Int32 nDialogResult)
1922
                    {
1923
                        if (!nDialogResult)
1924
                        {
1925
                            pDlg->disposeOnce();
1926
                            return;
1927
                        }
1928
1929
                        lcl_callXScript(xFrame, pDlg->GetScriptModel(), pDlg->GetScriptURL());
1930
                        pDlg->disposeOnce();
1931
                    });
1932
                pDlg->LoadLastUsedMacro();
1933
            }
1934
            rReq.Done();
1935
        }
1936
        break;
1937
#endif // HAVE_FEATURE_SCRIPTING
1938
1939
0
        case SID_OFFICE_CHECK_PLZ:
1940
0
        {
1941
0
            bool bRet = false;
1942
0
            const SfxStringItem* pStringItem = rReq.GetArg<SfxStringItem>(rReq.GetSlot());
1943
1944
0
            if ( pStringItem )
1945
0
            {
1946
0
                bRet = true /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
1947
0
            }
1948
#if HAVE_FEATURE_SCRIPTING
1949
            else
1950
                SbxBase::SetError( ERRCODE_BASIC_WRONG_ARGS );
1951
#endif
1952
0
            rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
1953
0
        }
1954
0
        break;
1955
1956
0
        case SID_AUTO_CORRECT_DLG:
1957
0
        {
1958
0
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1959
0
            SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG>(GetPool()));
1960
0
            const SfxPoolItem* pItem=nullptr;
1961
0
            const SfxItemSet* pSet = rReq.GetArgs();
1962
0
            if ( pSet && pSet->GetItemState( SID_AUTO_CORRECT_DLG, false, &pItem ) == SfxItemState::SET )
1963
0
                aSet.Put( *pItem );
1964
1965
0
            ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateAutoCorrTabDialog(rReq.GetFrameWeld(), &aSet));
1966
0
            pDlg->Execute();
1967
1968
0
            break;
1969
0
        }
1970
1971
0
        case SID_NEWSD :
1972
0
        {
1973
0
            if (!SvtModuleOptions().IsImpressInstalled())
1974
0
            {
1975
0
                std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(rReq.GetFrameWeld(),
1976
0
                                                                         VclMessageType::Warning, VclButtonsType::Ok,
1977
0
                                                                         SfxResId(STR_MODULENOTINSTALLED)));
1978
0
                xBox->run();
1979
0
                return;
1980
0
            }
1981
1982
0
            const Reference< uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext();
1983
0
            Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
1984
1985
0
            OUString aCmd = GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName();
1986
0
            Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
1987
0
            Sequence < beans::PropertyValue > aSeq;
1988
0
            if ( rReq.GetArgs() )
1989
0
                aSeq = TransformItems(rReq.GetSlot(), *rReq.GetArgs()).getAsConstPropertyValueList();
1990
0
            Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
1991
0
            frame::DispatchResultEvent aEvent;
1992
0
            bool bSuccess = (aResult >>= aEvent) &&
1993
0
                                (aEvent.State == frame::DispatchResultState::SUCCESS);
1994
0
            rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
1995
0
        }
1996
0
        break;
1997
1998
0
        case FN_LABEL :
1999
0
        case FN_BUSINESS_CARD :
2000
0
        case FN_XFORMS_INIT :
2001
0
        {
2002
0
            const Reference< uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext();
2003
0
            Reference< frame::XDispatchProvider > xProv = text::ModuleDispatcher::create( xContext );
2004
2005
0
            OUString aCmd = GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName();
2006
0
            Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
2007
0
            Sequence < beans::PropertyValue > aSeq;
2008
0
            if ( rReq.GetArgs() )
2009
0
                aSeq = TransformItems(rReq.GetSlot(), *rReq.GetArgs()).getAsConstPropertyValueList();
2010
0
            Any aResult = xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aSeq );
2011
0
            frame::DispatchResultEvent aEvent;
2012
0
            bool bSuccess = (aResult >>= aEvent) &&
2013
0
                                (aEvent.State == frame::DispatchResultState::SUCCESS);
2014
0
            rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
2015
0
        }
2016
0
        break;
2017
2018
0
        case SID_ADDRESS_DATA_SOURCE:
2019
0
        {
2020
0
            try
2021
0
            {
2022
0
                const Reference< uno::XComponentContext >& xORB = ::comphelper::getProcessComponentContext();
2023
0
                Reference< ui::dialogs::XExecutableDialog > xDialog = ui::dialogs::AddressBookSourcePilot::createWithParent(xORB, nullptr);
2024
0
                xDialog->execute();
2025
0
            }
2026
0
            catch(const css::uno::Exception&)
2027
0
            {
2028
0
                DBG_UNHANDLED_EXCEPTION("sfx.appl");
2029
0
            }
2030
0
        }
2031
0
        break;
2032
2033
0
        case SID_COMP_BIBLIOGRAPHY:
2034
0
            lcl_tryLoadBibliography();
2035
0
        break;
2036
0
    }
2037
0
}
2038
2039
void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
2040
0
{
2041
0
    if (!SvtModuleOptions().IsWriterInstalled())
2042
0
    {
2043
0
        rSet.DisableItem( FN_LABEL );
2044
0
        rSet.DisableItem( FN_BUSINESS_CARD );
2045
0
        rSet.DisableItem( FN_XFORMS_INIT );
2046
0
    }
2047
0
    if ( comphelper::LibreOfficeKit::isActive() )
2048
0
        rSet.DisableItem( SID_AUTO_CORRECT_DLG );
2049
2050
0
    if (SvtSecurityOptions::IsMacroDisabled())
2051
0
    {
2052
0
        rSet.DisableItem(SID_RUNMACRO);
2053
0
        rSet.DisableItem(SID_MACROORGANIZER);
2054
0
        rSet.DisableItem(SID_SCRIPTORGANIZER);
2055
0
        rSet.DisableItem(SID_BASICIDE_APPEAR);
2056
0
        rSet.DisableItem(SID_MACROMANAGER);
2057
0
    }
2058
0
}
2059
2060
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */