LibreOffice Module basic (master) 1
basrdll.cxx
Go to the documentation of this file.
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 <vcl/svapp.hxx>
24#include <tools/debug.hxx>
25#include <vcl/weld.hxx>
26
27#include <basic/sbstar.hxx>
28#include <basic/basrdll.hxx>
29#include <strings.hrc>
30#include <sbxbase.hxx>
31#include <config_features.h>
32
33namespace
34{
35struct BasicDLLImpl : public SvRefBase
36{
37 bool bDebugMode;
38 bool bBreakEnabled;
39
40 std::unique_ptr<SbxAppData> xSbxAppData;
41
42 BasicDLLImpl()
43 : bDebugMode(false)
44 , bBreakEnabled(true)
45 , xSbxAppData(new SbxAppData)
46 { }
47
48 static BasicDLLImpl* BASIC_DLL;
49 static std::mutex& getMutex()
50 {
51 static std::mutex aMutex;
52 return aMutex;
53 }
54};
55
56BasicDLLImpl* BasicDLLImpl::BASIC_DLL = nullptr;
57}
58
60{
61 std::scoped_lock aGuard(BasicDLLImpl::getMutex());
62 if (!BasicDLLImpl::BASIC_DLL)
63 BasicDLLImpl::BASIC_DLL = new BasicDLLImpl;
64 m_xImpl = BasicDLLImpl::BASIC_DLL;
65}
66
68{
69 std::scoped_lock aGuard(BasicDLLImpl::getMutex());
70 const bool bLastRef = m_xImpl->GetRefCount() == 1;
71 if (bLastRef) {
72 BasicDLLImpl::BASIC_DLL->xSbxAppData->m_aGlobErr.clear();
73 }
74 m_xImpl.clear();
75 // only reset BASIC_DLL after the object had been destroyed
76 if (bLastRef)
77 BasicDLLImpl::BASIC_DLL = nullptr;
78}
79
80void BasicDLL::EnableBreak( bool bEnable )
81{
82 DBG_ASSERT( BasicDLLImpl::BASIC_DLL, "BasicDLL::EnableBreak: No instance yet!" );
83 if (BasicDLLImpl::BASIC_DLL)
84 {
85 BasicDLLImpl::BASIC_DLL->bBreakEnabled = bEnable;
86 }
87}
88
89void BasicDLL::SetDebugMode( bool bDebugMode )
90{
91 DBG_ASSERT( BasicDLLImpl::BASIC_DLL, "BasicDLL::EnableBreak: No instance yet!" );
92 if (BasicDLLImpl::BASIC_DLL)
93 {
94 BasicDLLImpl::BASIC_DLL->bDebugMode = bDebugMode;
95 }
96}
97
98
100{
101 DBG_ASSERT( BasicDLLImpl::BASIC_DLL, "BasicDLL::EnableBreak: No instance yet!" );
102#if HAVE_FEATURE_SCRIPTING
103 if (!BasicDLLImpl::BASIC_DLL)
104 return;
105
106 // bJustStopping: if there's someone pressing STOP like crazy umpteen times,
107 // but the Basic doesn't stop early enough, the box might appear more often...
108 static bool bJustStopping = false;
109 if (StarBASIC::IsRunning() && !bJustStopping
110 && (BasicDLLImpl::BASIC_DLL->bBreakEnabled || BasicDLLImpl::BASIC_DLL->bDebugMode))
111 {
112 bJustStopping = true;
114 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(nullptr,
115 VclMessageType::Info, VclButtonsType::Ok,
116 BasResId(IDS_SBERR_TERMINATED)));
117 xInfoBox->run();
118 bJustStopping = false;
119 }
120#endif
121}
122
124{
125 return *BasicDLLImpl::BASIC_DLL->xSbxAppData;
126}
127
129{
130 return BasicDLLImpl::BASIC_DLL && BasicDLLImpl::BASIC_DLL->xSbxAppData;
131}
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsSbxData_Impl()
returns true if the SbxAppData is still valid, used to check if we are in shutdown.
Definition: basrdll.cxx:128
SbxAppData & GetSbxData_Impl()
Definition: basrdll.cxx:123
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
~BasicDLL()
Definition: basrdll.cxx:67
static void SetDebugMode(bool bDebugMode)
Definition: basrdll.cxx:89
static void BasicBreak()
Definition: basrdll.cxx:99
tools::SvRef< SvRefBase > m_xImpl
Definition: basrdll.hxx:29
BasicDLL()
Definition: basrdll.cxx:59
static void EnableBreak(bool bEnable)
Definition: basrdll.cxx:80
static bool IsRunning()
Definition: sb.cxx:1364
static void Stop()
Definition: sb.cxx:1357
#define DBG_ASSERT(sCon, aError)
::osl::Mutex & getMutex()
std::mutex aMutex
OUString BasResId(TranslateId aId)
Definition: sbxscan.cxx:432