LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vbahelper/source/vbahelper - vbalineformat.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 192 35.9 %
Date: 2013-07-09 Functions: 14 31 45.2 %
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 <ooo/vba/office/MsoArrowheadStyle.hpp>
      20             : #include <ooo/vba/office/MsoArrowheadLength.hpp>
      21             : #include <ooo/vba/office/MsoArrowheadWidth.hpp>
      22             : #include <ooo/vba/office/MsoLineDashStyle.hpp>
      23             : #include <com/sun/star/drawing/LineStyle.hpp>
      24             : #include <com/sun/star/drawing/LineDash.hpp>
      25             : #include "vbalineformat.hxx"
      26             : #include "vbacolorformat.hxx"
      27             : 
      28             : using namespace ooo::vba;
      29             : using namespace com::sun::star;
      30             : 
      31          12 : ScVbaLineFormat::ScVbaLineFormat( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape > xShape ) : ScVbaLineFormat_BASE( xParent, xContext ), m_xShape( xShape )
      32             : {
      33          12 :     m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
      34          12 :     m_nLineDashStyle = office::MsoLineDashStyle::msoLineSolid;
      35          12 :     m_nLineWeight = 1;
      36          12 : }
      37             : 
      38             : sal_Int32
      39           0 : ScVbaLineFormat::convertLineStartEndNameToArrowheadStyle( OUString sLineName )
      40             : {
      41           0 :     sal_Int32 nLineType = office::MsoArrowheadStyle::msoArrowheadNone;
      42           0 :     if ( sLineName == "Small Arrow" || sLineName == "Arrow" || sLineName == "msArrowEnd" || sLineName == "Double Arrow")
      43             :     {
      44             :         // msoArrowheadTriangle
      45           0 :         nLineType = office::MsoArrowheadStyle::msoArrowheadTriangle;
      46             :     }
      47           0 :     else if ( sLineName == "Square 45" || sLineName == "Square" || sLineName == "msArrowDiamondEnd")
      48             :     {
      49             :         // msoArrowheadDiamond
      50           0 :         nLineType = office::MsoArrowheadStyle::msoArrowheadDiamond;
      51             :     }
      52           0 :     else if (sLineName == "Circle" || sLineName == "msArrowOvalEnd" || sLineName == "Dimension Lines" )
      53             :     {
      54             :         // msoArrowheadOval
      55           0 :         nLineType = office::MsoArrowheadStyle::msoArrowheadOval;
      56             :     }
      57           0 :     else if ( sLineName == "Arrow concave" || sLineName == "msArrowStealthEnd" )
      58             :     {
      59             :         // msoArrowheadStealth
      60           0 :         nLineType = office::MsoArrowheadStyle::msoArrowheadStealth;
      61             :     }
      62           0 :     else if ( sLineName == "Rounded short Arrow" || sLineName == "Rounded large Arrow" || sLineName == "Symmetric Arrow"
      63           0 :            || sLineName == "msArrowOpenEnd" || sLineName == "Line Arrow" )
      64             :     {
      65             :         // msoArrowheadOpen
      66           0 :         nLineType = office::MsoArrowheadStyle::msoArrowheadOpen;
      67             :     }
      68             :     else
      69             :     {
      70             :         // msoArrowheadNone
      71           0 :         nLineType = office::MsoArrowheadStyle::msoArrowheadNone;
      72             :     }
      73           0 :     return nLineType;
      74             : }
      75             : 
      76             : OUString
      77           0 : ScVbaLineFormat::convertArrowheadStyleToLineStartEndName( sal_Int32 nArrowheadStyle ) throw (uno::RuntimeException)
      78             : {
      79           0 :     switch( nArrowheadStyle )
      80             :     {
      81             :         case office::MsoArrowheadStyle::msoArrowheadNone:
      82           0 :             return OUString();
      83             :         case office::MsoArrowheadStyle::msoArrowheadStealth:
      84           0 :             return OUString("Arrow concave");
      85             :         case office::MsoArrowheadStyle::msoArrowheadOpen:
      86           0 :             return OUString("Line Arrow");
      87             :         case office::MsoArrowheadStyle::msoArrowheadOval:
      88           0 :             return  OUString("Circle");
      89             :         case office::MsoArrowheadStyle::msoArrowheadDiamond:
      90           0 :             return OUString("Square 45");
      91             :         case office::MsoArrowheadStyle::msoArrowheadTriangle:
      92           0 :             return OUString("Arrow");
      93             :         default:
      94           0 :             throw uno::RuntimeException( "Invalid Arrow Style!" , uno::Reference< uno::XInterface >() );
      95             :     }
      96             : }
      97             : 
      98             : // Attributes
      99             : sal_Int32 SAL_CALL
     100           0 : ScVbaLineFormat::getBeginArrowheadStyle() throw (uno::RuntimeException)
     101             : {
     102           0 :     sal_Int32 nLineType = office::MsoArrowheadStyle::msoArrowheadNone;
     103           0 :     OUString sLineName;
     104           0 :     m_xPropertySet->getPropertyValue( "LineStartName" ) >>= sLineName;
     105           0 :     if( ( sLineName.getLength() > 7 ) && ( sLineName.indexOf( "msArray" ) ) != -1 )
     106             :     {
     107           0 :         sal_Int32 nIndex = sLineName.indexOf( ' ' );
     108           0 :         OUString sName = sLineName.copy( 0, nIndex );
     109             :         //sal_Int32 nSize = sLineName.copy( nIndex + 1 ).toInt32();
     110           0 :         nLineType = convertLineStartEndNameToArrowheadStyle( sName );
     111             :     }
     112             :     else
     113             :     {
     114           0 :         nLineType = convertLineStartEndNameToArrowheadStyle( sLineName );
     115             :     }
     116           0 :     return nLineType;
     117             : }
     118             : 
     119             : void SAL_CALL
     120           0 : ScVbaLineFormat::setBeginArrowheadStyle( sal_Int32 _beginarrowheadstyle ) throw (uno::RuntimeException)
     121             : {
     122           0 :     OUString sArrayName = convertArrowheadStyleToLineStartEndName( _beginarrowheadstyle );
     123           0 :     m_xPropertySet->setPropertyValue( "LineStartName" , uno::makeAny( sArrayName ) );
     124           0 : }
     125             : 
     126             : sal_Int32 SAL_CALL
     127           0 : ScVbaLineFormat::getBeginArrowheadLength() throw (uno::RuntimeException)
     128             : {
     129             :     // #STUB
     130             :     // force error
     131           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     132             : }
     133             : 
     134             : void SAL_CALL
     135           0 : ScVbaLineFormat::setBeginArrowheadLength( sal_Int32 /*_beginarrowheadlength*/ ) throw (uno::RuntimeException)
     136             : {
     137             :     // #STUB
     138             :     // force error
     139           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     140             : }
     141             : 
     142             : sal_Int32 SAL_CALL
     143           0 : ScVbaLineFormat::getBeginArrowheadWidth() throw (uno::RuntimeException)
     144             : {
     145             :     // #STUB
     146             :     // force error
     147           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     148             : }
     149             : 
     150             : void SAL_CALL
     151           0 : ScVbaLineFormat::setBeginArrowheadWidth( sal_Int32 /*_beginarrowheadwidth*/ ) throw (uno::RuntimeException)
     152             : {
     153             :     // #STUB
     154             :     // force error
     155           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     156             : }
     157             : 
     158             : sal_Int32 SAL_CALL
     159           0 : ScVbaLineFormat::getEndArrowheadStylel() throw (uno::RuntimeException)
     160             : {
     161             :     // #STUB
     162           0 :     return 0;
     163             : }
     164             : 
     165             : void SAL_CALL
     166           0 : ScVbaLineFormat::setEndArrowheadStylel( sal_Int32 /*_endarrowheadstylel*/ ) throw (uno::RuntimeException)
     167             : {
     168             :     // #STUB
     169           0 : }
     170             : 
     171             : sal_Int32 SAL_CALL
     172           0 : ScVbaLineFormat::getEndArrowheadLength() throw (uno::RuntimeException)
     173             : {
     174             :     // #STUB
     175             :     // force error
     176           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     177             : }
     178             : 
     179             : void SAL_CALL
     180           0 : ScVbaLineFormat::setEndArrowheadLength( sal_Int32 /*_endarrowheadlength*/ ) throw (uno::RuntimeException)
     181             : {
     182             :     // #STUB
     183           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     184             : }
     185             : 
     186             : sal_Int32 SAL_CALL
     187           0 : ScVbaLineFormat::getEndArrowheadWidth() throw (uno::RuntimeException)
     188             : {
     189             :     // #STUB
     190           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     191             : }
     192             : 
     193             : void SAL_CALL
     194           0 : ScVbaLineFormat::setEndArrowheadWidth( sal_Int32 /*_endarrowheadwidth*/ ) throw (uno::RuntimeException)
     195             : {
     196             :     // #STUB
     197           0 :     throw uno::RuntimeException( "Property 'EndArrowheadWidth' is not supported." , uno::Reference< uno::XInterface >() );
     198             : }
     199             : 
     200             : double SAL_CALL
     201           0 : ScVbaLineFormat::getWeight() throw (uno::RuntimeException)
     202             : {
     203           0 :     sal_Int32 nLineWidth=0;
     204           0 :     m_xPropertySet->getPropertyValue( "LineWidth" ) >>= nLineWidth;
     205           0 :     double dLineWidth = Millimeter::getInPoints( nLineWidth );
     206           0 :     return dLineWidth;
     207             : }
     208             : 
     209             : void SAL_CALL
     210           1 : ScVbaLineFormat::setWeight( double _weight ) throw (uno::RuntimeException)
     211             : {
     212           1 :     if( _weight < 0 )
     213           0 :         throw uno::RuntimeException( "Parameter: Must be positive." , uno::Reference< uno::XInterface >() );
     214           1 :     if( _weight == 0 )
     215           0 :         _weight = 0.5;
     216           1 :     m_nLineWeight = _weight;
     217           1 :     Millimeter aMillimeter;
     218           1 :     aMillimeter.setInPoints( _weight );
     219             : 
     220           1 :     sal_Int32 nLineWidth = static_cast<sal_Int32>( aMillimeter.getInHundredthsOfOneMillimeter() );
     221           1 :     m_xPropertySet->setPropertyValue( "LineWidth" , uno::makeAny( nLineWidth ) );
     222           1 :     setDashStyle( m_nLineDashStyle );
     223           1 : }
     224             : 
     225             : sal_Bool SAL_CALL
     226           1 : ScVbaLineFormat::getVisible() throw (uno::RuntimeException)
     227             : {
     228             :     drawing::LineStyle aLineStyle;
     229           1 :     m_xPropertySet->getPropertyValue( "LineStyle" ) >>= aLineStyle;
     230           1 :     if( aLineStyle == drawing::LineStyle_NONE )
     231             :     {
     232           0 :         return sal_False;
     233             :     }
     234           1 :     return sal_True;
     235             : }
     236             : 
     237             : void SAL_CALL
     238           1 : ScVbaLineFormat::setVisible( sal_Bool _visible ) throw (uno::RuntimeException)
     239             : {
     240             :     drawing::LineStyle aLineStyle;
     241           1 :     m_xPropertySet->getPropertyValue( "LineStyle" ) >>= aLineStyle;
     242           1 :     if( !_visible )
     243             :     {
     244           0 :         aLineStyle = drawing::LineStyle_NONE;
     245           0 :         m_xPropertySet->setPropertyValue( "LineStyle" , uno::makeAny( aLineStyle ) );
     246             :     }
     247             :     else
     248             :     {
     249           1 :         if( aLineStyle == drawing::LineStyle_NONE )
     250             :         {
     251           0 :             setDashStyle( m_nLineDashStyle );
     252             :         }
     253             :     }
     254           1 : }
     255             : 
     256             : double SAL_CALL
     257           1 : ScVbaLineFormat::getTransparency() throw (uno::RuntimeException)
     258             : {
     259           1 :     sal_Int16 nTransparency = 0;
     260           1 :     m_xPropertySet->getPropertyValue( "LineTransparence" ) >>= nTransparency;
     261           1 :     double fTransparency = static_cast<double>( nTransparency );
     262           1 :     return fTransparency / 100;
     263             : }
     264             : 
     265             : void SAL_CALL
     266           1 : ScVbaLineFormat::setTransparency( double _transparency ) throw (uno::RuntimeException)
     267             : {
     268           1 :     sal_Int16 nTransparency = static_cast<sal_Int16>( _transparency * 100 );
     269           1 :     m_xPropertySet->setPropertyValue( "LineTransparence" , uno::makeAny( nTransparency ) );
     270           1 : }
     271             : 
     272             : sal_Int16 SAL_CALL
     273           1 : ScVbaLineFormat::getStyle() throw (uno::RuntimeException)
     274             : {
     275             :     //OpenOffice.org only supports one LineStyle (other than the DashStyles)
     276             :     //Therefore we can only return the SingleLine
     277           1 :     return 1;
     278             : }
     279             : 
     280             : void SAL_CALL
     281           1 : ScVbaLineFormat::setStyle( sal_Int16 /*_style */) throw (uno::RuntimeException)
     282             : {
     283             :     //OpenOffice.org only supports one LineStyle (other than the DashStyles)
     284             :     //Therefore we do not set the LineStyle, because it maybe is already set
     285             :     //to Dashed or Single Line. Setting the 'Visible' or 'DashStyle' properties
     286             :     //will be done with the according methods.
     287             : 
     288             :     // #STUB
     289           1 : }
     290             : 
     291             : sal_Int32 SAL_CALL
     292           1 : ScVbaLineFormat::getDashStyle() throw (uno::RuntimeException)
     293             : {
     294             :     drawing::LineStyle eLineStyle;
     295             :     //LineStyle integer in Xray
     296           1 :     m_xPropertySet->getPropertyValue( "LineStyle" ) >>= eLineStyle;
     297           1 :     if( eLineStyle == drawing::LineStyle_SOLID )
     298           0 :         m_nLineDashStyle = office::MsoLineDashStyle::msoLineSolid;
     299             :     else
     300             :     {
     301           1 :         drawing::LineDash aLineDash;
     302           1 :         m_xPropertySet->getPropertyValue( "LineDash" ) >>= aLineDash;
     303           1 :         if( aLineDash.Dots == 0 )
     304             :         {
     305             :             //LineDash
     306             :             //LineLongDash
     307           0 :             m_nLineDashStyle = office::MsoLineDashStyle::msoLineDash;
     308           0 :             if( aLineDash.Distance > 0 && ( aLineDash.DashLen / aLineDash.Distance > 1 ) )
     309             :             {
     310           0 :                 m_nLineDashStyle = office::MsoLineDashStyle::msoLineLongDash;
     311             :             }
     312             :         }
     313           1 :         else if( aLineDash.Dots == 1 )
     314             :         {
     315             :             // LineDashDot
     316             :             // LineLongDashDot
     317             :             // LineSquareDot
     318             :             // LineRoundDot ! not supported
     319           0 :             m_nLineDashStyle = office::MsoLineDashStyle::msoLineDashDot;
     320           0 :             if( aLineDash.Dashes == 0 )
     321             :             {
     322           0 :                 m_nLineDashStyle = office::MsoLineDashStyle::msoLineSquareDot;
     323             :             }
     324             :             else
     325             :             {
     326           0 :                 if( aLineDash.Distance > 0 && ( aLineDash.DashLen / aLineDash.Distance > 1 ) )
     327             :                 {
     328           0 :                     m_nLineDashStyle = office::MsoLineDashStyle::msoLineLongDashDot;
     329             :                 }
     330             :             }
     331             :         }
     332           1 :         else if( aLineDash.Dots == 2 )
     333             :         {
     334             :             // LineDashDotDot
     335           1 :             m_nLineDashStyle = office::MsoLineDashStyle::msoLineDashDotDot;
     336             :         }
     337             :     }
     338             : 
     339           1 :     return m_nLineDashStyle;
     340             : }
     341             : 
     342             : void SAL_CALL
     343           2 : ScVbaLineFormat::setDashStyle( sal_Int32 _dashstyle ) throw (uno::RuntimeException)
     344             : {
     345           2 :     m_nLineDashStyle = _dashstyle;
     346           2 :     if( _dashstyle == office::MsoLineDashStyle::msoLineSolid )
     347             :     {
     348           1 :         m_xPropertySet->setPropertyValue( "LineStyle" , uno::makeAny( drawing::LineStyle_SOLID  ));
     349             :     }
     350             :     else
     351             :     {
     352           1 :         m_xPropertySet->setPropertyValue( "LineStyle" , uno::makeAny( drawing::LineStyle_DASH ) );
     353           1 :         drawing::LineDash  pLineDash;
     354           1 :         Millimeter aMillimeter( m_nLineWeight );
     355           1 :         sal_Int32 nPixel = static_cast< sal_Int32 >( aMillimeter.getInHundredthsOfOneMillimeter() );
     356           1 :         switch( _dashstyle )
     357             :         {
     358             :         case office::MsoLineDashStyle::msoLineDashDot:
     359           0 :             pLineDash.Dots = 1;
     360           0 :             pLineDash.DotLen = nPixel;
     361           0 :             pLineDash.Dashes = 1;
     362           0 :             pLineDash.DashLen = 5 * nPixel;
     363           0 :             pLineDash.Distance = 4 * nPixel;
     364           0 :             break;
     365             :         case office::MsoLineDashStyle::msoLineLongDashDot:
     366           0 :             pLineDash.Dots = 1;
     367           0 :             pLineDash.DotLen = nPixel;
     368           0 :             pLineDash.Dashes = 1;
     369           0 :             pLineDash.DashLen = 10 * nPixel;
     370           0 :             pLineDash.Distance = 4 * nPixel;
     371           0 :             break;
     372             :         case office::MsoLineDashStyle::msoLineDash:
     373           0 :             pLineDash.Dots = 0;
     374           0 :             pLineDash.DotLen = 0;
     375           0 :             pLineDash.Dashes = 1;
     376           0 :             pLineDash.DashLen = 6 * nPixel;
     377           0 :             pLineDash.Distance = 4 * nPixel;
     378           0 :             break;
     379             :         case office::MsoLineDashStyle::msoLineDashDotDot:
     380           1 :             pLineDash.Dots = 2;
     381           1 :             pLineDash.DotLen = nPixel;
     382           1 :             pLineDash.Dashes = 1;
     383           1 :             pLineDash.DashLen = 10 * nPixel;
     384           1 :             pLineDash.Distance = 3 * nPixel;
     385           1 :             break;
     386             :         case office::MsoLineDashStyle::msoLineLongDash:
     387           0 :             pLineDash.Dots = 0;
     388           0 :             pLineDash.DotLen = 0;
     389           0 :             pLineDash.Dashes = 1;
     390           0 :             pLineDash.DashLen = 10 * nPixel;
     391           0 :             pLineDash.Distance = 4 * nPixel;
     392           0 :             break;
     393             :         case office::MsoLineDashStyle::msoLineSquareDot:
     394           0 :             pLineDash.Dots = 1;
     395           0 :             pLineDash.DotLen = nPixel;
     396           0 :             pLineDash.Dashes = 0;
     397           0 :             pLineDash.DashLen = 0;
     398           0 :             pLineDash.Distance = nPixel;
     399           0 :             break;
     400             :         case office::MsoLineDashStyle::msoLineRoundDot:
     401           0 :             pLineDash.Dots = 1;
     402           0 :             pLineDash.DotLen = nPixel;
     403           0 :             pLineDash.Dashes = 0;
     404           0 :             pLineDash.DashLen = 0;
     405           0 :             pLineDash.Distance = nPixel;
     406           0 :             break;
     407             :         default:
     408           0 :             throw uno::RuntimeException( "this MsoLineDashStyle is not supported." , uno::Reference< uno::XInterface >() );
     409             :         }
     410           1 :         m_xPropertySet->setPropertyValue( "LineDash" , uno::makeAny( pLineDash ) );
     411             :     }
     412           2 : }
     413             : 
     414             : // Methods
     415             : uno::Reference< msforms::XColorFormat > SAL_CALL
     416           1 : ScVbaLineFormat::BackColor() throw (uno::RuntimeException)
     417             : {
     418           1 :     return uno::Reference< msforms::XColorFormat >( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ::ColorFormatType::LINEFORMAT_BACKCOLOR ) );
     419             : }
     420             : 
     421             : uno::Reference< msforms::XColorFormat > SAL_CALL
     422           2 : ScVbaLineFormat::ForeColor() throw (uno::RuntimeException)
     423             : {
     424           2 :     return uno::Reference< msforms::XColorFormat >( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ::ColorFormatType::LINEFORMAT_FORECOLOR ) );
     425             : }
     426             : 
     427             : OUString
     428           0 : ScVbaLineFormat::getServiceImplName()
     429             : {
     430           0 :     return OUString("ScVbaLineFormat");
     431             : }
     432             : 
     433             : uno::Sequence< OUString >
     434           0 : ScVbaLineFormat::getServiceNames()
     435             : {
     436           0 :     static uno::Sequence< OUString > aServiceNames;
     437           0 :     if ( aServiceNames.getLength() == 0 )
     438             :     {
     439           0 :         aServiceNames.realloc( 1 );
     440           0 :         aServiceNames[ 0 ] = "ooo.vba.msform.LineFormat";
     441             :     }
     442           0 :     return aServiceNames;
     443         186 : }
     444             : 
     445             : 
     446             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10