LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/data - sheetevents.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 54 0.0 %
Date: 2012-12-27 Functions: 0 10 0.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             : 
      24           0 : rtl::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 rtl::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 rtl::OUString::createFromAscii(aEventNames[nEvent]);
      43             : }
      44             : 
      45           0 : sal_Int32 ScSheetEvents::GetVbaSheetEventId(sal_Int32 nEvent)
      46             : {
      47             :     using namespace ::com::sun::star::script::vba::VBAEventId;
      48           0 :     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           0 :     return nVbaEventIds[nEvent];
      65             : }
      66             : 
      67           0 : sal_Int32 ScSheetEvents::GetVbaDocumentEventId(sal_Int32 nEvent)
      68             : {
      69             :     using namespace ::com::sun::star::script::vba::VBAEventId;
      70           0 :     sal_Int32 nSheetEventId = GetVbaSheetEventId(nEvent);
      71           0 :     return (nSheetEventId != NO_EVENT) ? (nSheetEventId + USERDEFINED_START) : NO_EVENT;
      72             : }
      73             : 
      74             : // -----------------------------------------------------------------------
      75             : 
      76           0 : ScSheetEvents::ScSheetEvents() :
      77           0 :     mpScriptNames(NULL)
      78             : {
      79           0 : }
      80             : 
      81           0 : ScSheetEvents::~ScSheetEvents()
      82             : {
      83           0 :     Clear();
      84           0 : }
      85             : 
      86           0 : void ScSheetEvents::Clear()
      87             : {
      88           0 :     if (mpScriptNames)
      89             :     {
      90           0 :         for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
      91           0 :             delete mpScriptNames[nEvent];
      92           0 :         delete[] mpScriptNames;
      93           0 :         mpScriptNames = NULL;
      94             :     }
      95           0 : }
      96             : 
      97           0 : ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther) :
      98           0 :     mpScriptNames(NULL)
      99             : {
     100           0 :     *this = rOther;
     101           0 : }
     102             : 
     103           0 : const ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther)
     104             : {
     105           0 :     Clear();
     106           0 :     if (rOther.mpScriptNames)
     107             :     {
     108           0 :         mpScriptNames = new rtl::OUString*[SC_SHEETEVENT_COUNT];
     109           0 :         for (sal_Int32 nEvent=0; nEvent<SC_SHEETEVENT_COUNT; ++nEvent)
     110           0 :             if (rOther.mpScriptNames[nEvent])
     111           0 :                 mpScriptNames[nEvent] = new rtl::OUString(*rOther.mpScriptNames[nEvent]);
     112             :             else
     113           0 :                 mpScriptNames[nEvent] = NULL;
     114             :     }
     115           0 :     return *this;
     116             : }
     117             : 
     118           0 : const rtl::OUString* ScSheetEvents::GetScript(sal_Int32 nEvent) const
     119             : {
     120           0 :     if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
     121             :     {
     122             :         OSL_FAIL("invalid event number");
     123           0 :         return NULL;
     124             :     }
     125             : 
     126           0 :     if (mpScriptNames)
     127           0 :         return mpScriptNames[nEvent];
     128           0 :     return NULL;
     129             : }
     130             : 
     131           0 : void ScSheetEvents::SetScript(sal_Int32 nEvent, const rtl::OUString* pNew)
     132             : {
     133           0 :     if (nEvent<0 || nEvent>=SC_SHEETEVENT_COUNT)
     134             :     {
     135             :         OSL_FAIL("invalid event number");
     136           0 :         return;
     137             :     }
     138             : 
     139           0 :     if (!mpScriptNames)
     140             :     {
     141           0 :         mpScriptNames = new rtl::OUString*[SC_SHEETEVENT_COUNT];
     142           0 :         for (sal_Int32 nEventIdx=0; nEventIdx<SC_SHEETEVENT_COUNT; ++nEventIdx)
     143           0 :             mpScriptNames[nEventIdx] = NULL;
     144             :     }
     145           0 :     delete mpScriptNames[nEvent];
     146           0 :     if (pNew)
     147           0 :         mpScriptNames[nEvent] = new rtl::OUString(*pNew);
     148             :     else
     149           0 :         mpScriptNames[nEvent] = NULL;
     150             : }
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10