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

Generated by: LCOV version 1.11