Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/basic/source/runtime/basrdll.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 <memory>
21
#include <mutex>
22
23
#include <unotools/resmgr.hxx>
24
#include <vcl/svapp.hxx>
25
#include <vcl/vclenum.hxx>
26
#include <tools/debug.hxx>
27
#include <vcl/weld/MessageDialog.hxx>
28
29
#include <basic/sbstar.hxx>
30
#include <basic/basrdll.hxx>
31
#include <strings.hrc>
32
#include <sbxbase.hxx>
33
#include <config_features.h>
34
35
namespace
36
{
37
struct BasicDLLImpl : public SvRefBase
38
{
39
    bool        bDebugMode;
40
    bool        bBreakEnabled;
41
42
    SbxAppData aSbxAppData;
43
44
    BasicDLLImpl()
45
26
        : bDebugMode(false)
46
26
        , bBreakEnabled(true)
47
26
    { }
48
49
    static BasicDLLImpl* BASIC_DLL;
50
    static std::mutex& getMutex()
51
26
    {
52
26
        static std::mutex aMutex;
53
26
        return aMutex;
54
26
    }
55
};
56
57
BasicDLLImpl* BasicDLLImpl::BASIC_DLL = nullptr;
58
}
59
60
BasicDLL::BasicDLL()
61
26
{
62
26
    std::scoped_lock aGuard(BasicDLLImpl::getMutex());
63
26
    if (!BasicDLLImpl::BASIC_DLL)
64
26
        BasicDLLImpl::BASIC_DLL = new BasicDLLImpl;
65
26
    m_xImpl = BasicDLLImpl::BASIC_DLL;
66
26
}
67
68
BasicDLL::~BasicDLL()
69
0
{
70
0
    std::scoped_lock aGuard(BasicDLLImpl::getMutex());
71
0
    const bool bLastRef = m_xImpl->GetRefCount() == 1;
72
0
    if (bLastRef) {
73
0
        BasicDLLImpl::BASIC_DLL->aSbxAppData.m_aGlobErr.clear();
74
0
    }
75
0
    m_xImpl.clear();
76
    // only reset BASIC_DLL after the object had been destroyed
77
0
    if (bLastRef)
78
0
        BasicDLLImpl::BASIC_DLL = nullptr;
79
0
}
80
81
void BasicDLL::EnableBreak( bool bEnable )
82
0
{
83
0
    DBG_ASSERT( BasicDLLImpl::BASIC_DLL, "BasicDLL::EnableBreak: No instance yet!" );
84
0
    if (BasicDLLImpl::BASIC_DLL)
85
0
    {
86
0
        BasicDLLImpl::BASIC_DLL->bBreakEnabled = bEnable;
87
0
    }
88
0
}
89
90
void BasicDLL::SetDebugMode( bool bDebugMode )
91
0
{
92
0
    DBG_ASSERT( BasicDLLImpl::BASIC_DLL, "BasicDLL::EnableBreak: No instance yet!" );
93
0
    if (BasicDLLImpl::BASIC_DLL)
94
0
    {
95
0
        BasicDLLImpl::BASIC_DLL->bDebugMode = bDebugMode;
96
0
    }
97
0
}
98
99
100
void BasicDLL::BasicBreak()
101
0
{
102
0
    DBG_ASSERT( BasicDLLImpl::BASIC_DLL, "BasicDLL::EnableBreak: No instance yet!" );
103
#if HAVE_FEATURE_SCRIPTING
104
    if (!BasicDLLImpl::BASIC_DLL)
105
        return;
106
107
    // bJustStopping: if there's someone pressing STOP like crazy umpteen times,
108
    // but the Basic doesn't stop early enough, the box might appear more often...
109
    static bool bJustStopping = false;
110
    if (StarBASIC::IsRunning() && !bJustStopping
111
        && (BasicDLLImpl::BASIC_DLL->bBreakEnabled || BasicDLLImpl::BASIC_DLL->bDebugMode))
112
    {
113
        bJustStopping = true;
114
        StarBASIC::Stop();
115
        std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(nullptr,
116
                                                      VclMessageType::Info, VclButtonsType::Ok,
117
                                                      BasResId(IDS_SBERR_TERMINATED)));
118
        xInfoBox->run();
119
        bJustStopping = false;
120
    }
121
#endif
122
0
}
123
124
SbxAppData& GetSbxData_Impl()
125
166k
{
126
166k
    return BasicDLLImpl::BASIC_DLL->aSbxAppData;
127
166k
}
128
129
bool IsSbxData_Impl()
130
0
{
131
0
    return BasicDLLImpl::BASIC_DLL;
132
0
}
133
134
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */