LibreOffice Module sc (master) 1
sheetevents.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 <sheetevents.hxx>
21#include <com/sun/star/script/vba/VBAEventId.hpp>
22#include <optional>
23
25{
26 static const char* aEventNames[] =
27 {
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
35 };
36 return OUString::createFromAscii(aEventNames[static_cast<int>(nEvent)]);
37}
38
40{
41 using namespace ::com::sun::star::script::vba::VBAEventId;
42
43 static const sal_Int32 nVbaEventIds[] =
44 {
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
52 };
53 return nVbaEventIds[static_cast<int>(nEvent)];
54}
55
56const int COUNT = static_cast<int>(ScSheetEventId::COUNT);
57
59{
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;
63}
64
66{
67}
68
70{
71 Clear();
72}
73
75{
76 mpScriptNames.reset();
77}
78
80{
81 *this = rOther;
82}
83
85{
86 if (this != &rOther)
87 {
88 Clear();
89 if (rOther.mpScriptNames)
90 {
91 mpScriptNames.reset( new std::optional<OUString>[COUNT] );
92 for (sal_Int32 nEvent=0; nEvent<COUNT; ++nEvent)
93 mpScriptNames[nEvent] = rOther.mpScriptNames[nEvent];
94 }
95 }
96 return *this;
97}
98
99const OUString* ScSheetEvents::GetScript(ScSheetEventId nEvent) const
100{
101 if (mpScriptNames)
102 {
103 std::optional<OUString> const & r = mpScriptNames[static_cast<int>(nEvent)];
104 if (r)
105 return &*r;
106 }
107 return nullptr;
108}
109
110void ScSheetEvents::SetScript(ScSheetEventId eEvent, const OUString* pNew)
111{
112 int nEvent = static_cast<int>(eEvent);
113 if (!mpScriptNames)
114 {
115 mpScriptNames.reset( new std::optional<OUString>[COUNT] );
116 }
117 if (pNew)
118 mpScriptNames[nEvent] = *pNew;
119 else
120 mpScriptNames[nEvent].reset();
121}
122
123/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString * GetScript(ScSheetEventId nEvent) const
Definition: sheetevents.cxx:99
static sal_Int32 GetVbaDocumentEventId(ScSheetEventId nEvent)
Definition: sheetevents.cxx:58
std::unique_ptr< std::optional< OUString >[]> mpScriptNames
Definition: sheetevents.hxx:34
static sal_Int32 GetVbaSheetEventId(ScSheetEventId nEvent)
Definition: sheetevents.cxx:39
ScSheetEvents & operator=(const ScSheetEvents &rOther)
Definition: sheetevents.cxx:84
static OUString GetEventName(ScSheetEventId nEvent)
Definition: sheetevents.cxx:24
void SetScript(ScSheetEventId nEvent, const OUString *pNew)
@ COUNT
all values, including non-numerical values, are counted.
const int COUNT
Definition: sheetevents.cxx:56
ScSheetEventId
Definition: sheetevents.hxx:27