LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbapalette.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 19 28 67.9 %
Date: 2015-06-13 12:38:46 Functions: 9 12 75.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 "vbapalette.hxx"
      21             : 
      22             : #include <sal/macros.h>
      23             : #include <cppuhelper/implbase1.hxx>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/container/XIndexAccess.hpp>
      26             : #include "excelvbahelper.hxx"
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::ooo::vba;
      30             : 
      31             : /** Standard EGA colors, bright. */
      32             : #define EXC_PALETTE_EGA_COLORS_LIGHT \
      33             :             0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF
      34             : /** Standard EGA colors, dark. */
      35             : #define EXC_PALETTE_EGA_COLORS_DARK \
      36             :             0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080
      37             : 
      38             : static const ColorData spnDefColorTable8[] =
      39             : {
      40             : /*  8 */    EXC_PALETTE_EGA_COLORS_LIGHT,
      41             : /* 16 */    EXC_PALETTE_EGA_COLORS_DARK,
      42             : /* 24 */    0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF,
      43             : /* 32 */    0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
      44             : /* 40 */    0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99,
      45             : /* 48 */    0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
      46             : /* 56 */    0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333
      47             : };
      48             : 
      49             : typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE;
      50             : 
      51          40 : class DefaultPalette : public XIndexAccess_BASE
      52             : {
      53             : public:
      54          20 :    DefaultPalette(){}
      55             : 
      56             :     // Methods XIndexAccess
      57         143 :     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      58             :     {
      59         143 :         return sizeof(spnDefColorTable8) / sizeof(spnDefColorTable8[0]);
      60             :     }
      61             : 
      62         135 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      63             :     {
      64         135 :         if ( Index < 0 || Index >= getCount() )
      65           0 :             throw lang::IndexOutOfBoundsException();
      66         135 :         return uno::makeAny( sal_Int32( spnDefColorTable8[ Index ] ) );
      67             :     }
      68             : 
      69             :     // Methods XElementAcess
      70           0 :     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      71             :     {
      72           0 :         return ::cppu::UnoType<sal_Int32>::get();
      73             :     }
      74           0 :     virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      75             :     {
      76           0 :         return sal_True;
      77             :     }
      78             : 
      79             : };
      80             : 
      81           0 : ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) :
      82           0 :     m_pShell( excel::getDocShell( rxModel ) )
      83             : {
      84           0 : }
      85             : 
      86             : uno::Reference< container::XIndexAccess >
      87           2 : ScVbaPalette::getDefaultPalette()
      88             : {
      89           2 :     return new DefaultPalette();
      90             : }
      91             : 
      92             : uno::Reference< container::XIndexAccess >
      93          18 : ScVbaPalette::getPalette() const
      94             : {
      95          18 :     uno::Reference< container::XIndexAccess > xIndex;
      96          36 :     uno::Reference< beans::XPropertySet > xProps;
      97          18 :     if ( m_pShell )
      98          18 :         xProps.set( m_pShell->GetModel(), uno::UNO_QUERY_THROW );
      99             :     else
     100           0 :         throw uno::RuntimeException("Can't extract palette, no doc shell" );
     101          18 :     xIndex.set( xProps->getPropertyValue("ColorPalette"), uno::UNO_QUERY );
     102          18 :     if ( !xIndex.is() )
     103          18 :         return new DefaultPalette();
     104          18 :     return xIndex;
     105           9 : }
     106             : 
     107             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11