Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/appl/appdata.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <config_features.h>
21
22
#include <appdata.hxx>
23
#include <sfx2/tbxctrl.hxx>
24
#include <sfx2/stbitem.hxx>
25
#include <sfx2/childwin.hxx>
26
#include <sfx2/doctempl.hxx>
27
#include <sfx2/module.hxx>
28
#include <sfx2/sidebar/Theme.hxx>
29
#include <sfx2/objsh.hxx>
30
#include <appbaslib.hxx>
31
#include <unoctitm.hxx>
32
#include <svl/svdde.hxx>
33
34
#include <basic/basicmanagerrepository.hxx>
35
#include <basic/basmgr.hxx>
36
#include <basic/basrdll.hxx>
37
38
using ::basic::BasicManagerRepository;
39
using ::basic::BasicManagerCreationListener;
40
using ::com::sun::star::uno::Reference;
41
using ::com::sun::star::frame::XModel;
42
using ::com::sun::star::uno::XInterface;
43
44
static BasicDLL* pBasic = nullptr;
45
46
class SfxBasicManagerCreationListener : public ::basic::BasicManagerCreationListener
47
{
48
private:
49
    SfxAppData_Impl& m_rAppData;
50
51
public:
52
    explicit SfxBasicManagerCreationListener(SfxAppData_Impl& _rAppData)
53
27
        : m_rAppData(_rAppData)
54
27
    {
55
27
    }
56
57
    virtual ~SfxBasicManagerCreationListener();
58
59
    virtual void onBasicManagerCreated( const Reference< XModel >& _rxForDocument, BasicManager& _rBasicManager ) override;
60
};
61
62
SfxBasicManagerCreationListener::~SfxBasicManagerCreationListener()
63
0
{
64
0
}
65
66
void SfxBasicManagerCreationListener::onBasicManagerCreated( const Reference< XModel >& _rxForDocument, BasicManager& _rBasicManager )
67
0
{
68
0
    if ( _rxForDocument == nullptr )
69
0
        m_rAppData.OnApplicationBasicManagerCreated( _rBasicManager );
70
0
}
71
72
SfxAppData_Impl::SfxAppData_Impl()
73
27
    : pPool(nullptr)
74
27
    , pProgress(nullptr)
75
27
    , nDocModalMode(0)
76
27
    , nRescheduleLocks(0)
77
27
    , pBasicManager( new SfxBasicManagerHolder )
78
27
    , pBasMgrListener( new SfxBasicManagerCreationListener( *this ) )
79
27
    , pViewFrame( nullptr )
80
27
    , bDowning( true )
81
27
    , bInQuit( false )
82
27
    , bClosingDocs( false )
83
84
27
{
85
27
    pBasic = new BasicDLL;
86
87
#if HAVE_FEATURE_SCRIPTING
88
    BasicManagerRepository::registerCreationListener( *pBasMgrListener );
89
#endif
90
27
}
91
92
SfxAppData_Impl::~SfxAppData_Impl()
93
0
{
94
0
    DeInitDDE();
95
0
    pBasicManager.reset();
96
97
#if HAVE_FEATURE_SCRIPTING
98
    BasicManagerRepository::revokeCreationListener( *pBasMgrListener );
99
    pBasMgrListener.reset();
100
#endif
101
102
0
    delete pBasic;
103
0
}
104
105
SfxDocumentTemplates* SfxAppData_Impl::GetDocumentTemplates()
106
0
{
107
0
    if ( !pTemplates )
108
0
        pTemplates.emplace();
109
0
    else
110
0
        pTemplates->ReInitFromComponent();
111
0
    return &*pTemplates;
112
0
}
113
114
void SfxAppData_Impl::OnApplicationBasicManagerCreated( BasicManager& _rBasicManager )
115
0
{
116
0
#if !HAVE_FEATURE_SCRIPTING
117
0
    (void) _rBasicManager;
118
#else
119
    pBasicManager->reset( &_rBasicManager );
120
121
    // global constants, additionally to the ones already added by createApplicationBasicManager:
122
    // ThisComponent
123
    Reference< XInterface > xCurrentComponent = SfxObjectShell::GetCurrentComponent();
124
    _rBasicManager.SetGlobalUNOConstant( u"ThisComponent"_ustr, css::uno::Any( xCurrentComponent ) );
125
#endif
126
0
}
127
128
void SfxAppData_Impl::MoveShellToFirstShell(SfxViewShell& rShell)
129
4.02k
{
130
    // Move associated ViewShell to the top of the ViewShells stack
131
    // so the ViewShells are in order of most recently active
132
    // ViewFrames. SfxViewShell::Current() should be equal to
133
    // SfxViewShell::GetFirst(false) if SfxViewShell::Current() is
134
    // not-null.
135
4.02k
    const auto shellIt = std::find(maViewShells.begin(), maViewShells.end(), &rShell);
136
4.02k
    if (shellIt != maViewShells.end() && shellIt != maViewShells.begin())
137
0
    {
138
0
        maViewShells.erase(shellIt);
139
0
        maViewShells.insert(maViewShells.begin(), &rShell);
140
0
    }
141
4.02k
}
142
143
void SfxAppData_Impl::MoveFrameToFirstFrame(SfxViewFrame& rFrame)
144
4.02k
{
145
4.02k
    const auto frameIt = std::find(maViewFrames.begin(), maViewFrames.end(), &rFrame);
146
4.02k
    if (frameIt != maViewFrames.end() && frameIt != maViewFrames.begin())
147
0
    {
148
0
        maViewFrames.erase(frameIt);
149
0
        maViewFrames.insert(maViewFrames.begin(), &rFrame);
150
0
    }
151
4.02k
}
152
153
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */