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 <boost/optional.hpp>
23
GetEventName(ScSheetEventId nEvent)24 OUString ScSheetEvents::GetEventName(ScSheetEventId nEvent)
25 {
26 static const sal_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
GetVbaSheetEventId(ScSheetEventId nEvent)39 sal_Int32 ScSheetEvents::GetVbaSheetEventId(ScSheetEventId nEvent)
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
56 static const int COUNT = static_cast<int>(ScSheetEventId::COUNT);
57
GetVbaDocumentEventId(ScSheetEventId nEvent)58 sal_Int32 ScSheetEvents::GetVbaDocumentEventId(ScSheetEventId nEvent)
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
ScSheetEvents()65 ScSheetEvents::ScSheetEvents()
66 {
67 }
68
~ScSheetEvents()69 ScSheetEvents::~ScSheetEvents()
70 {
71 Clear();
72 }
73
Clear()74 void ScSheetEvents::Clear()
75 {
76 mpScriptNames.reset();
77 }
78
ScSheetEvents(const ScSheetEvents & rOther)79 ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther)
80 {
81 *this = rOther;
82 }
83
operator =(const ScSheetEvents & rOther)84 ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther)
85 {
86 if (this != &rOther)
87 {
88 Clear();
89 if (rOther.mpScriptNames)
90 {
91 mpScriptNames.reset( new boost::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
GetScript(ScSheetEventId nEvent) const99 const OUString* ScSheetEvents::GetScript(ScSheetEventId nEvent) const
100 {
101 if (mpScriptNames)
102 {
103 boost::optional<OUString> const & r = mpScriptNames[static_cast<int>(nEvent)];
104 if (r)
105 return &*r;
106 }
107 return nullptr;
108 }
109
SetScript(ScSheetEventId eEvent,const OUString * pNew)110 void ScSheetEvents::SetScript(ScSheetEventId eEvent, const OUString* pNew)
111 {
112 int nEvent = static_cast<int>(eEvent);
113 if (!mpScriptNames)
114 {
115 mpScriptNames.reset( new boost::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: */
124