tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / core / data / sheetevents.cxx
blob7d2152226b68e1f66ac6a0e3bbbe3e6f27d83c6e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sheetevents.hxx>
21 #include <com/sun/star/script/vba/VBAEventId.hpp>
22 #include <optional>
24 OUString ScSheetEvents::GetEventName(ScSheetEventId nEvent)
26 static const char* aEventNames[] =
28 "OnFocus", // SC_SHEETEVENT_FOCUS
29 "OnUnfocus", // SC_SHEETEVENT_UNFOCUS
30 "OnSelect", // SC_SHEETEVENT_SELECT
31 "OnDoubleClick", // SC_SHEETEVENT_DOUBLECLICK
32 "OnRightClick", // SC_SHEETEVENT_RIGHTCLICK
33 "OnChange", // SC_SHEETEVENT_CHANGE
34 "OnCalculate" // SC_SHEETEVENT_CALCULATE
36 return OUString::createFromAscii(aEventNames[static_cast<int>(nEvent)]);
39 sal_Int32 ScSheetEvents::GetVbaSheetEventId(ScSheetEventId nEvent)
41 using namespace ::com::sun::star::script::vba::VBAEventId;
43 static const sal_Int32 nVbaEventIds[] =
45 WORKSHEET_ACTIVATE, // SC_SHEETEVENT_FOCUS
46 WORKSHEET_DEACTIVATE, // SC_SHEETEVENT_UNFOCUS
47 WORKSHEET_SELECTIONCHANGE, // SC_SHEETEVENT_SELECT
48 WORKSHEET_BEFOREDOUBLECLICK, // SC_SHEETEVENT_DOUBLECLICK
49 WORKSHEET_BEFORERIGHTCLICK, // SC_SHEETEVENT_RIGHTCLICK
50 WORKSHEET_CHANGE, // SC_SHEETEVENT_CHANGE
51 WORKSHEET_CALCULATE // SC_SHEETEVENT_CALCULATE
53 return nVbaEventIds[static_cast<int>(nEvent)];
56 const int COUNT = static_cast<int>(ScSheetEventId::COUNT);
58 sal_Int32 ScSheetEvents::GetVbaDocumentEventId(ScSheetEventId nEvent)
60 using namespace ::com::sun::star::script::vba::VBAEventId;
61 sal_Int32 nSheetEventId = GetVbaSheetEventId(nEvent);
62 return (nSheetEventId != NO_EVENT) ? (nSheetEventId + USERDEFINED_START) : NO_EVENT;
65 ScSheetEvents::ScSheetEvents()
69 ScSheetEvents::~ScSheetEvents()
71 Clear();
74 void ScSheetEvents::Clear()
76 mpScriptNames.reset();
79 ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther)
81 *this = rOther;
84 ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther)
86 if (this != &rOther)
88 Clear();
89 if (rOther.mpScriptNames)
91 mpScriptNames.reset( new std::optional<OUString>[COUNT] );
92 for (sal_Int32 nEvent=0; nEvent<COUNT; ++nEvent)
93 mpScriptNames[nEvent] = rOther.mpScriptNames[nEvent];
96 return *this;
99 const OUString* ScSheetEvents::GetScript(ScSheetEventId nEvent) const
101 if (mpScriptNames)
103 std::optional<OUString> const & r = mpScriptNames[static_cast<int>(nEvent)];
104 if (r)
105 return &*r;
107 return nullptr;
110 void ScSheetEvents::SetScript(ScSheetEventId eEvent, const OUString* pNew)
112 int nEvent = static_cast<int>(eEvent);
113 if (!mpScriptNames)
115 mpScriptNames.reset( new std::optional<OUString>[COUNT] );
117 if (pNew)
118 mpScriptNames[nEvent] = *pNew;
119 else
120 mpScriptNames[nEvent].reset();
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */