1*b3f79822SAndrew Rist /**************************************************************
2*b3f79822SAndrew Rist *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "sheetevents.hxx"
30cdf0e10cSrcweir #include <com/sun/star/script/vba/VBAEventId.hpp>
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir // -----------------------------------------------------------------------
34cdf0e10cSrcweir
35cdf0e10cSrcweir // static
GetEventName(sal_Int32 nEvent)36cdf0e10cSrcweir rtl::OUString ScSheetEvents::GetEventName(sal_Int32 nEvent)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
39cdf0e10cSrcweir {
40cdf0e10cSrcweir DBG_ERRORFILE("invalid event number");
41cdf0e10cSrcweir return rtl::OUString();
42cdf0e10cSrcweir }
43cdf0e10cSrcweir
44cdf0e10cSrcweir static const sal_Char* aEventNames[] =
45cdf0e10cSrcweir {
46cdf0e10cSrcweir "OnFocus", // SC_SHEETEVENT_FOCUS
47cdf0e10cSrcweir "OnUnfocus", // SC_SHEETEVENT_UNFOCUS
48cdf0e10cSrcweir "OnSelect", // SC_SHEETEVENT_SELECT
49cdf0e10cSrcweir "OnDoubleClick", // SC_SHEETEVENT_DOUBLECLICK
50cdf0e10cSrcweir "OnRightClick", // SC_SHEETEVENT_RIGHTCLICK
51cdf0e10cSrcweir "OnChange", // SC_SHEETEVENT_CHANGE
52cdf0e10cSrcweir "OnCalculate" // SC_SHEETEVENT_CALCULATE
53cdf0e10cSrcweir };
54cdf0e10cSrcweir return rtl::OUString::createFromAscii(aEventNames[nEvent]);
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
57cdf0e10cSrcweir // static
GetVbaSheetEventId(sal_Int32 nEvent)58cdf0e10cSrcweir sal_Int32 ScSheetEvents::GetVbaSheetEventId(sal_Int32 nEvent)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir using namespace ::com::sun::star::script::vba::VBAEventId;
61cdf0e10cSrcweir if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir DBG_ERRORFILE("invalid event number");
64cdf0e10cSrcweir return NO_EVENT;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir static const sal_Int32 nVbaEventIds[] =
68cdf0e10cSrcweir {
69cdf0e10cSrcweir WORKSHEET_ACTIVATE, // SC_SHEETEVENT_FOCUS
70cdf0e10cSrcweir WORKSHEET_DEACTIVATE, // SC_SHEETEVENT_UNFOCUS
71cdf0e10cSrcweir WORKSHEET_SELECTIONCHANGE, // SC_SHEETEVENT_SELECT
72cdf0e10cSrcweir WORKSHEET_BEFOREDOUBLECLICK, // SC_SHEETEVENT_DOUBLECLICK
73cdf0e10cSrcweir WORKSHEET_BEFORERIGHTCLICK, // SC_SHEETEVENT_RIGHTCLICK
74cdf0e10cSrcweir WORKSHEET_CHANGE, // SC_SHEETEVENT_CHANGE
75cdf0e10cSrcweir WORKSHEET_CALCULATE // SC_SHEETEVENT_CALCULATE
76cdf0e10cSrcweir };
77cdf0e10cSrcweir return nVbaEventIds[nEvent];
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
80cdf0e10cSrcweir // static
GetVbaDocumentEventId(sal_Int32 nEvent)81cdf0e10cSrcweir sal_Int32 ScSheetEvents::GetVbaDocumentEventId(sal_Int32 nEvent)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir using namespace ::com::sun::star::script::vba::VBAEventId;
84cdf0e10cSrcweir sal_Int32 nSheetEventId = GetVbaSheetEventId(nEvent);
85cdf0e10cSrcweir return (nSheetEventId != NO_EVENT) ? (nSheetEventId + USERDEFINED_START) : NO_EVENT;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir // -----------------------------------------------------------------------
89cdf0e10cSrcweir
ScSheetEvents()90cdf0e10cSrcweir ScSheetEvents::ScSheetEvents() :
91cdf0e10cSrcweir mpScriptNames(NULL)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
~ScSheetEvents()95cdf0e10cSrcweir ScSheetEvents::~ScSheetEvents()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir Clear();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
Clear()100cdf0e10cSrcweir void ScSheetEvents::Clear()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir if (mpScriptNames)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
105cdf0e10cSrcweir delete mpScriptNames[nEvent];
106cdf0e10cSrcweir delete[] mpScriptNames;
107cdf0e10cSrcweir mpScriptNames = NULL;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
ScSheetEvents(const ScSheetEvents & rOther)111cdf0e10cSrcweir ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther) :
112cdf0e10cSrcweir mpScriptNames(NULL)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir *this = rOther;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
operator =(const ScSheetEvents & rOther)117cdf0e10cSrcweir const ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir Clear();
120cdf0e10cSrcweir if (rOther.mpScriptNames)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir mpScriptNames = new rtl::OUString*[SC_SHEETEVENT_COUNT];
123cdf0e10cSrcweir for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
124cdf0e10cSrcweir if (rOther.mpScriptNames[nEvent])
125cdf0e10cSrcweir mpScriptNames[nEvent] = new rtl::OUString(*rOther.mpScriptNames[nEvent]);
126cdf0e10cSrcweir else
127cdf0e10cSrcweir mpScriptNames[nEvent] = NULL;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir return *this;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
GetScript(sal_Int32 nEvent) const132cdf0e10cSrcweir const rtl::OUString* ScSheetEvents::GetScript(sal_Int32 nEvent) const
133cdf0e10cSrcweir {
134cdf0e10cSrcweir if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir DBG_ERRORFILE("invalid event number");
137cdf0e10cSrcweir return NULL;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir if (mpScriptNames)
141cdf0e10cSrcweir return mpScriptNames[nEvent];
142cdf0e10cSrcweir return NULL;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
SetScript(sal_Int32 nEvent,const rtl::OUString * pNew)145cdf0e10cSrcweir void ScSheetEvents::SetScript(sal_Int32 nEvent, const rtl::OUString* pNew)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir DBG_ERRORFILE("invalid event number");
150cdf0e10cSrcweir return;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir if (!mpScriptNames)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir mpScriptNames = new rtl::OUString*[SC_SHEETEVENT_COUNT];
156cdf0e10cSrcweir for (sal_Int32 nEventIdx=0; nEventIdx<SC_SHEETEVENT_COUNT; ++nEventIdx)
157cdf0e10cSrcweir mpScriptNames[nEventIdx] = NULL;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir delete mpScriptNames[nEvent];
160cdf0e10cSrcweir if (pNew)
161cdf0e10cSrcweir mpScriptNames[nEvent] = new rtl::OUString(*pNew);
162cdf0e10cSrcweir else
163cdf0e10cSrcweir mpScriptNames[nEvent] = NULL;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166