1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2008 by Sun Microsystems, Inc. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * $RCSfile: sheetdata.cxx,v $ 10 * $Revision: 1.69.32.3 $ 11 * 12 * This file is part of OpenOffice.org. 13 * 14 * OpenOffice.org is free software: you can redistribute it and/or modify 15 * it under the terms of the GNU Lesser General Public License version 3 16 * only, as published by the Free Software Foundation. 17 * 18 * OpenOffice.org is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU Lesser General Public License version 3 for more details 22 * (a copy is included in the LICENSE file that accompanied this code). 23 * 24 * You should have received a copy of the GNU Lesser General Public License 25 * version 3 along with OpenOffice.org. If not, see 26 * <http://www.openoffice.org/license.html> 27 * for a copy of the LGPLv3 License. 28 * 29 ************************************************************************/ 30 31 // MARKER(update_precomp.py): autogen include statement, do not remove 32 #include "precompiled_sc.hxx" 33 34 // INCLUDE --------------------------------------------------------------- 35 36 #include "sheetevents.hxx" 37 #include <com/sun/star/script/vba/VBAEventId.hpp> 38 #include <tools/debug.hxx> 39 40 // ----------------------------------------------------------------------- 41 42 // static 43 rtl::OUString ScSheetEvents::GetEventName(sal_Int32 nEvent) 44 { 45 if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT) 46 { 47 DBG_ERRORFILE("invalid event number"); 48 return rtl::OUString(); 49 } 50 51 static const sal_Char* aEventNames[] = 52 { 53 "OnFocus", // SC_SHEETEVENT_FOCUS 54 "OnUnfocus", // SC_SHEETEVENT_UNFOCUS 55 "OnSelect", // SC_SHEETEVENT_SELECT 56 "OnDoubleClick", // SC_SHEETEVENT_DOUBLECLICK 57 "OnRightClick", // SC_SHEETEVENT_RIGHTCLICK 58 "OnChange", // SC_SHEETEVENT_CHANGE 59 "OnCalculate" // SC_SHEETEVENT_CALCULATE 60 }; 61 return rtl::OUString::createFromAscii(aEventNames[nEvent]); 62 } 63 64 // static 65 sal_Int32 ScSheetEvents::GetVbaSheetEventId(sal_Int32 nEvent) 66 { 67 using namespace ::com::sun::star::script::vba::VBAEventId; 68 if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT) 69 { 70 DBG_ERRORFILE("invalid event number"); 71 return NO_EVENT; 72 } 73 74 static const sal_Int32 nVbaEventIds[] = 75 { 76 WORKSHEET_ACTIVATE, // SC_SHEETEVENT_FOCUS 77 WORKSHEET_DEACTIVATE, // SC_SHEETEVENT_UNFOCUS 78 WORKSHEET_SELECTIONCHANGE, // SC_SHEETEVENT_SELECT 79 WORKSHEET_BEFOREDOUBLECLICK, // SC_SHEETEVENT_DOUBLECLICK 80 WORKSHEET_BEFORERIGHTCLICK, // SC_SHEETEVENT_RIGHTCLICK 81 WORKSHEET_CHANGE, // SC_SHEETEVENT_CHANGE 82 WORKSHEET_CALCULATE // SC_SHEETEVENT_CALCULATE 83 }; 84 return nVbaEventIds[nEvent]; 85 } 86 87 // static 88 sal_Int32 ScSheetEvents::GetVbaDocumentEventId(sal_Int32 nEvent) 89 { 90 using namespace ::com::sun::star::script::vba::VBAEventId; 91 sal_Int32 nSheetEventId = GetVbaSheetEventId(nEvent); 92 return (nSheetEventId != NO_EVENT) ? (nSheetEventId + USERDEFINED_START) : NO_EVENT; 93 } 94 95 // ----------------------------------------------------------------------- 96 97 ScSheetEvents::ScSheetEvents() : 98 mpScriptNames(NULL) 99 { 100 } 101 102 ScSheetEvents::~ScSheetEvents() 103 { 104 Clear(); 105 } 106 107 void ScSheetEvents::Clear() 108 { 109 if (mpScriptNames) 110 { 111 for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent) 112 delete mpScriptNames[nEvent]; 113 delete[] mpScriptNames; 114 mpScriptNames = NULL; 115 } 116 } 117 118 ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther) : 119 mpScriptNames(NULL) 120 { 121 *this = rOther; 122 } 123 124 const ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther) 125 { 126 Clear(); 127 if (rOther.mpScriptNames) 128 { 129 mpScriptNames = new rtl::OUString*[SC_SHEETEVENT_COUNT]; 130 for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent) 131 if (rOther.mpScriptNames[nEvent]) 132 mpScriptNames[nEvent] = new rtl::OUString(*rOther.mpScriptNames[nEvent]); 133 else 134 mpScriptNames[nEvent] = NULL; 135 } 136 return *this; 137 } 138 139 const rtl::OUString* ScSheetEvents::GetScript(sal_Int32 nEvent) const 140 { 141 if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT) 142 { 143 DBG_ERRORFILE("invalid event number"); 144 return NULL; 145 } 146 147 if (mpScriptNames) 148 return mpScriptNames[nEvent]; 149 return NULL; 150 } 151 152 void ScSheetEvents::SetScript(sal_Int32 nEvent, const rtl::OUString* pNew) 153 { 154 if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT) 155 { 156 DBG_ERRORFILE("invalid event number"); 157 return; 158 } 159 160 if (!mpScriptNames) 161 { 162 mpScriptNames = new rtl::OUString*[SC_SHEETEVENT_COUNT]; 163 for (sal_Int32 nEventIdx=0; nEventIdx<SC_SHEETEVENT_COUNT; ++nEventIdx) 164 mpScriptNames[nEventIdx] = NULL; 165 } 166 delete mpScriptNames[nEvent]; 167 if (pNew) 168 mpScriptNames[nEvent] = new rtl::OUString(*pNew); 169 else 170 mpScriptNames[nEvent] = NULL; 171 } 172 173