LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vbahelper/source/vbahelper - vbacolorformat.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 61 77.0 %
Date: 2013-07-09 Functions: 8 10 80.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             : #include <com/sun/star/beans/XPropertySet.hpp>
      20             : #include <ooo/vba/msforms/XLineFormat.hpp>
      21             : #include "vbacolorformat.hxx"
      22             : 
      23             : using namespace ooo::vba;
      24             : using namespace com::sun::star;
      25             : 
      26             : sal_Int32
      27          18 : MsoColorIndizes::getColorIndex( sal_Int32 nIndex )
      28             : {
      29             :     const static sal_Int32 COLORINDIZES[56] =
      30             :     {   HAPICOLOR_BLACK, HAPICOLOR_WITHE, HAPICOLOR_RED, HAPICOLOR_BRIGHTGREEN, HAPICOLOR_BLUE, HAPICOLOR_YELLOW, HAPICOLOR_PINK,
      31             :         HAPICOLOR_TURQUOISE, HAPICOLOR_DARKRED, HAPICOLOR_GREEN, HAPICOLOR_DARKBLUE, HAPICOLOR_DARKYELLOW, HAPICOLOR_VIOLET,
      32             :         HAPICOLOR_TEAL, HAPICOLOR_GRAY_25_PERCENT, HAPICOLOR_GRAY_50_PERCENT, HAPICOLOR_PERIWINCKLE, HAPICOLOR_PLUM,
      33             :         HAPICOLOR_IVORY, HAPICOLOR_LIGHTTURQUOISE, HAPICOLOR_DARKPRUPLE, HAPICOLOR_CORAL, HAPICOLOR_OCEANBLUE, HAPICOLOR_ICEBLUE,
      34             :         HAPICOLOR_GREEN, HAPICOLOR_PINK, HAPICOLOR_YELLOW, HAPICOLOR_TURQUOISE, HAPICOLOR_VIOLET, HAPICOLOR_DARKRED, HAPICOLOR_TEAL,
      35             :         HAPICOLOR_BLUE, HAPICOLOR_SKYBLUE, HAPICOLOR_LIGHTTURQUOISE, HAPICOLOR_LIGHTGREEN, HAPICOLOR_LIGHTYELLOW, HAPICOLOR_PALEBLUE,
      36             :         HAPICOLOR_ROSE, HAPICOLOR_LAVENDER, HAPICOLOR_TAN, HAPICOLOR_LIGHTBLUE, HAPICOLOR_AQUA, HAPICOLOR_LIME, HAPICOLOR_GOLD,
      37             :         HAPICOLOR_LIGHTORANGE, HAPICOLOR_ORANGE, HAPICOLOR_BLUEGRAY, HAPICOLOR_GRAY_40_PERCENT, HAPICOLOR_DARKTEAL,
      38             :         HAPICOLOR_SEAGREEN, HAPICOLOR_NONAME, HAPICOLOR_OLIVEGREEN, HAPICOLOR_BROWN, HAPICOLOR_PLUM, HAPICOLOR_INDIGO,
      39             :         HAPICOLOR_GRAY_80_PERCENT
      40             :     };
      41          18 :     return COLORINDIZES[nIndex];
      42             : }
      43          10 : ScVbaColorFormat::ScVbaColorFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XHelperInterface > xInternalParent, const uno::Reference< drawing::XShape > xShape, const sal_Int16 nColorFormatType ) : ScVbaColorFormat_BASE( xParent, xContext ), m_xInternalParent( xInternalParent ), m_xShape( xShape ), m_nColorFormatType( nColorFormatType )
      44             : {
      45          10 :     m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
      46          10 :     m_nFillFormatBackColor = 0;
      47             :     try
      48             :     {
      49          10 :         uno::Reference< ov::msforms::XFillFormat > xFillFormat( xInternalParent, uno::UNO_QUERY_THROW );
      50           7 :         m_pFillFormat = ( ScVbaFillFormat* )( xFillFormat.get() );
      51           6 :     }catch ( uno::RuntimeException& )
      52             :     {
      53           3 :         m_pFillFormat = NULL;
      54             :     }
      55          10 : }
      56             : 
      57             : // Attribute
      58             : sal_Int32 SAL_CALL
      59           5 : ScVbaColorFormat::getRGB() throw (uno::RuntimeException)
      60             : {
      61           5 :     sal_Int32 nRGB = 0;
      62           5 :     switch( m_nColorFormatType )
      63             :     {
      64             :     case ColorFormatType::LINEFORMAT_FORECOLOR:
      65           1 :         m_xPropertySet->getPropertyValue( "LineColor" ) >>= nRGB;
      66           1 :         break;
      67             :     case ColorFormatType::LINEFORMAT_BACKCOLOR:
      68             :         //TODO BackColor not supported
      69             :         // m_xPropertySet->setPropertyValue("Color", uno::makeAny( nRGB ) );
      70           0 :         break;
      71             :     case ColorFormatType::FILLFORMAT_FORECOLOR:
      72           4 :         m_xPropertySet->getPropertyValue( "FillColor" ) >>= nRGB;
      73           4 :         break;
      74             :     case ColorFormatType::FILLFORMAT_BACKCOLOR:
      75           0 :         nRGB = m_nFillFormatBackColor;
      76           0 :         break;
      77             :     default:
      78           0 :         throw uno::RuntimeException( "Second parameter of ColorFormat is wrong." , uno::Reference< uno::XInterface >() );
      79             :     }
      80           5 :     nRGB = OORGBToXLRGB( nRGB );
      81           5 :     return nRGB;
      82             : }
      83             : 
      84             : void SAL_CALL
      85           6 : ScVbaColorFormat::setRGB( sal_Int32 _rgb ) throw (uno::RuntimeException)
      86             : {
      87           6 :     sal_Int32 nRGB = XLRGBToOORGB( _rgb );
      88           6 :     switch( m_nColorFormatType )
      89             :     {
      90             :     case ColorFormatType::LINEFORMAT_FORECOLOR:
      91           1 :         m_xPropertySet->setPropertyValue( "LineColor" , uno::makeAny( nRGB ) );
      92           1 :         break;
      93             :     case ColorFormatType::LINEFORMAT_BACKCOLOR:
      94             :         // TODO BackColor not supported
      95           1 :         break;
      96             :     case ColorFormatType::FILLFORMAT_FORECOLOR:
      97           2 :         m_xPropertySet->setPropertyValue( "FillColor" , uno::makeAny( nRGB ) );
      98           2 :         if( m_pFillFormat )
      99             :         {
     100           2 :             m_pFillFormat->setForeColorAndInternalStyle(nRGB);
     101             :         }
     102           2 :         break;
     103             :     case ColorFormatType::FILLFORMAT_BACKCOLOR:
     104           2 :         m_nFillFormatBackColor = nRGB;
     105           2 :         if( m_pFillFormat )
     106             :         {
     107           2 :             m_pFillFormat->setForeColorAndInternalStyle(nRGB);
     108             :         }
     109           2 :         break;
     110             :     default:
     111           0 :         throw uno::RuntimeException( "Second parameter of ColorFormat is wrong." , uno::Reference< uno::XInterface >() );
     112             :     }
     113           6 : }
     114             : 
     115             : sal_Int32 SAL_CALL
     116           1 : ScVbaColorFormat::getSchemeColor() throw (uno::RuntimeException)
     117             : {
     118           1 :     sal_Int32 nColor = getRGB();
     119             :     // #TODO I guess the number of elements is determined by the correct scheme
     120             :     // the implementation here seems to be a rehash of color index ( which seems to be a
     121             :     // different thing ) - I would guess we need to know/import etc. the correct color scheme
     122             :     // or at least find out a little more
     123           1 :     sal_Int32 i = 0;
     124          16 :     for( ; i < 56; i++ )
     125             :     {
     126          16 :         if( nColor == MsoColorIndizes::getColorIndex(i) )
     127           1 :        break;
     128             :     }
     129             : 
     130           1 :     if( i == 56 ) // this is most likely an error condition
     131           0 :         --i;
     132           1 :     return i;
     133             :     // #TODO figure out what craziness is this,
     134             :     // the 56 colors seems incorrect, as in default XL ( 2003 ) there are 80 colors
     135             : /*
     136             :     if( i == 56 )
     137             :     {
     138             :         i = -2;
     139             :     }
     140             : 
     141             :     return ( i + 2 );
     142             : */
     143             : }
     144             : 
     145             : void SAL_CALL
     146           2 : ScVbaColorFormat::setSchemeColor( sal_Int32 _schemecolor ) throw (uno::RuntimeException)
     147             : {
     148             :     // the table is 0 based
     149           2 :     sal_Int32 nColor = MsoColorIndizes::getColorIndex( _schemecolor );
     150             :     // nColor is already xl RGB
     151           2 :     setRGB( nColor );
     152           2 : }
     153             : 
     154             : OUString
     155           0 : ScVbaColorFormat::getServiceImplName()
     156             : {
     157           0 :     return OUString("ScVbaColorFormat");
     158             : }
     159             : 
     160             : uno::Sequence< OUString >
     161           0 : ScVbaColorFormat::getServiceNames()
     162             : {
     163           0 :     static uno::Sequence< OUString > aServiceNames;
     164           0 :     if ( aServiceNames.getLength() == 0 )
     165             :     {
     166           0 :         aServiceNames.realloc( 1 );
     167           0 :         aServiceNames[ 0 ] = "ooo.vba.msforms.ColorFormat";
     168             :     }
     169           0 :     return aServiceNames;
     170         186 : }
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10