LCOV - code coverage report
Current view: top level - sc/source/core/data - sheetevents.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 6 54 11.1 %
Date: 2014-11-03 Functions: 2 10 20.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      23           0 : OUString ScSheetEvents::GetEventName(sal_Int32 nEvent)
      24             : {
      25           0 :     if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
      26             :     {
      27             :         OSL_FAIL("invalid event number");
      28           0 :         return OUString();
      29             :     }
      30             : 
      31             :     static const sal_Char* aEventNames[] =
      32             :     {
      33             :         "OnFocus",                  // SC_SHEETEVENT_FOCUS
      34             :         "OnUnfocus",                // SC_SHEETEVENT_UNFOCUS
      35             :         "OnSelect",                 // SC_SHEETEVENT_SELECT
      36             :         "OnDoubleClick",            // SC_SHEETEVENT_DOUBLECLICK
      37             :         "OnRightClick",             // SC_SHEETEVENT_RIGHTCLICK
      38             :         "OnChange",                 // SC_SHEETEVENT_CHANGE
      39             :         "OnCalculate"               // SC_SHEETEVENT_CALCULATE
      40             :     };
      41           0 :     return OUString::createFromAscii(aEventNames[nEvent]);
      42             : }
      43             : 
      44        2320 : sal_Int32 ScSheetEvents::GetVbaSheetEventId(sal_Int32 nEvent)
      45             : {
      46             :     using namespace ::com::sun::star::script::vba::VBAEventId;
      47        2320 :     if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
      48             :     {
      49             :         OSL_FAIL("invalid event number");
      50           0 :         return NO_EVENT;
      51             :     }
      52             : 
      53             :     static const sal_Int32 nVbaEventIds[] =
      54             :     {
      55             :         WORKSHEET_ACTIVATE,             // SC_SHEETEVENT_FOCUS
      56             :         WORKSHEET_DEACTIVATE,           // SC_SHEETEVENT_UNFOCUS
      57             :         WORKSHEET_SELECTIONCHANGE,      // SC_SHEETEVENT_SELECT
      58             :         WORKSHEET_BEFOREDOUBLECLICK,    // SC_SHEETEVENT_DOUBLECLICK
      59             :         WORKSHEET_BEFORERIGHTCLICK,     // SC_SHEETEVENT_RIGHTCLICK
      60             :         WORKSHEET_CHANGE,               // SC_SHEETEVENT_CHANGE
      61             :         WORKSHEET_CALCULATE             // SC_SHEETEVENT_CALCULATE
      62             :     };
      63        2320 :     return nVbaEventIds[nEvent];
      64             : }
      65             : 
      66         650 : sal_Int32 ScSheetEvents::GetVbaDocumentEventId(sal_Int32 nEvent)
      67             : {
      68             :     using namespace ::com::sun::star::script::vba::VBAEventId;
      69         650 :     sal_Int32 nSheetEventId = GetVbaSheetEventId(nEvent);
      70         650 :     return (nSheetEventId != NO_EVENT) ? (nSheetEventId + USERDEFINED_START) : NO_EVENT;
      71             : }
      72             : 
      73           0 : ScSheetEvents::ScSheetEvents() :
      74           0 :     mpScriptNames(NULL)
      75             : {
      76           0 : }
      77             : 
      78           0 : ScSheetEvents::~ScSheetEvents()
      79             : {
      80           0 :     Clear();
      81           0 : }
      82             : 
      83           0 : void ScSheetEvents::Clear()
      84             : {
      85           0 :     if (mpScriptNames)
      86             :     {
      87           0 :         for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
      88           0 :             delete mpScriptNames[nEvent];
      89           0 :         delete[] mpScriptNames;
      90           0 :         mpScriptNames = NULL;
      91             :     }
      92           0 : }
      93             : 
      94           0 : ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther) :
      95           0 :     mpScriptNames(NULL)
      96             : {
      97           0 :     *this = rOther;
      98           0 : }
      99             : 
     100           0 : const ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther)
     101             : {
     102           0 :     Clear();
     103           0 :     if (rOther.mpScriptNames)
     104             :     {
     105           0 :         mpScriptNames = new OUString*[SC_SHEETEVENT_COUNT];
     106           0 :         for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
     107           0 :             if (rOther.mpScriptNames[nEvent])
     108           0 :                 mpScriptNames[nEvent] = new OUString(*rOther.mpScriptNames[nEvent]);
     109             :             else
     110           0 :                 mpScriptNames[nEvent] = NULL;
     111             :     }
     112           0 :     return *this;
     113             : }
     114             : 
     115           0 : const OUString* ScSheetEvents::GetScript(sal_Int32 nEvent) const
     116             : {
     117           0 :     if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
     118             :     {
     119             :         OSL_FAIL("invalid event number");
     120           0 :         return NULL;
     121             :     }
     122             : 
     123           0 :     if (mpScriptNames)
     124           0 :         return mpScriptNames[nEvent];
     125           0 :     return NULL;
     126             : }
     127             : 
     128           0 : void ScSheetEvents::SetScript(sal_Int32 nEvent, const OUString* pNew)
     129             : {
     130           0 :     if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
     131             :     {
     132             :         OSL_FAIL("invalid event number");
     133           0 :         return;
     134             :     }
     135             : 
     136           0 :     if (!mpScriptNames)
     137             :     {
     138           0 :         mpScriptNames = new OUString*[SC_SHEETEVENT_COUNT];
     139           0 :         for (sal_Int32 nEventIdx=0; nEventIdx<SC_SHEETEVENT_COUNT; ++nEventIdx)
     140           0 :             mpScriptNames[nEventIdx] = NULL;
     141             :     }
     142           0 :     delete mpScriptNames[nEvent];
     143           0 :     if (pNew)
     144           0 :         mpScriptNames[nEvent] = new OUString(*pNew);
     145             :     else
     146           0 :         mpScriptNames[nEvent] = NULL;
     147             : }
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10